<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Isidro Hernandez on Medium]]></title>
        <description><![CDATA[Stories by Isidro Hernandez on Medium]]></description>
        <link>https://medium.com/@ihernandezjr?source=rss-5dc837edef50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*a7FgVfGuyVTkR53dVmOPSw.jpeg</url>
            <title>Stories by Isidro Hernandez on Medium</title>
            <link>https://medium.com/@ihernandezjr?source=rss-5dc837edef50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:38:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ihernandezjr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The CKAD Exam Question you haven’t seen!]]></title>
            <link>https://medium.com/swlh/the-ckad-exam-question-you-havent-seen-b434ba160093?source=rss-5dc837edef50------2</link>
            <guid isPermaLink="false">https://medium.com/p/b434ba160093</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Isidro Hernandez]]></dc:creator>
            <pubDate>Sun, 17 May 2020 03:18:44 GMT</pubDate>
            <atom:updated>2020-05-17T03:36:22.435Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SdlPrPylSJJ3FOq8RwKbQ.png" /><figcaption>Containers CKAD Docker Kubernetes</figcaption></figure><p>Over the last 60 days, I’ve had so much fun preparing for the <strong>CKAD</strong>. During that time the kubectl version had changed in the exam. Upon taking the exam I noticed that I prepared for mostly version 1.17. I wanted to share with you something that I noticed I had not seen before.</p><p>I saw a lot of changes to the kubectl commands. A lot of simplification of the use of kubectl run vs kubectl create. However, in this article, I wanted to cover the question that has eluded most if not all <strong><em>CKAD</em></strong> training, paid OR free.</p><p><strong><em>Introducing……</em></strong></p><h3>Deployment Rollout Strategy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*iGCkXzrAQehcmKLvHzKvcQ.png" /><figcaption>kubectl explain deployment.spec.strategy.rollingUpdate</figcaption></figure><p>How does the API docs define it?</p><pre>DESCRIPTION:</pre><pre>The deployment strategy to use to replace existing pods with new ones.</pre><pre>DeploymentStrategy describes how to replace existing pods with new ones.</pre><p>Let us create a deployment that can help us visualize this.</p><pre>apiVersion: extensions/v1beta1<br>kind: Deployment<br>metadata:<br>  name: testing-rolling-updates<br>spec:<br><strong>  replicas: 8<br></strong>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx-container<br>        image: nginx<br></pre><p>Create it with kubectl :</p><pre><strong>bash3$ kubectl create -f test.yaml<br>bash3$ kubectl get pods<br></strong>NAME                                       READY   STATUS              <br>testing-rolling-updates-5cdf4f57c7-24qqg   1/1     Running          testing-rolling-updates-5cdf4f57c7-g292n   1/1     Running            testing-rolling-updates-5cdf4f57c7-gmgpt   1/1     Running            testing-rolling-updates-5cdf4f57c7-mwdnb   1/1     Running            testing-rolling-updates-5cdf4f57c7-tm7vp   1/1     Running            testing-rolling-updates-5cdf4f57c7-tzz7j   1/1     Running            testing-rolling-updates-5cdf4f57c7-vb967   1/1     Running        testing-rolling-updates-5cdf4f57c7-vhmfs   1/1     Running            </pre><p>Ok, now we have something to work with. Let&#39;s break down what a <strong><em>Rolling Update Strategy</em></strong> is:</p><pre>FIELDS:</pre><pre><strong>maxSurge</strong> &lt;string&gt;</pre><pre>The maximum number of pods that can be scheduled <strong>above</strong> the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).</pre><p>The keyword for <strong>maxSurge</strong> is <strong><em>ABOVE. </em></strong>How many pods can we schedule <strong>ABOVE</strong> our desired pods (specified replicas)?</p><p>Values can be <strong><em>percentages</em></strong> or <strong><em>absolute numbers.</em></strong></p><p>So if we have 8 replicas what is the most amount that we want to have if we update the replicas? If we set this value to 40% that means anytime we update this deployment it can create 140% of 8 pods during the rollout. A total of 11.2 or 11 when we round it. When the rollout has finished, the pods will return to a count of 8 with the new changes we applied.</p><p>Let&#39;s move to maxUnavailable :</p><pre><strong>maxUnavailable</strong> &lt;string&gt;<br>     The maximum number of pods that can be unavailable during the <br>     update. Value can be an absolute number (ex: 5) or a percentage  <br>     of desired pods (ex: 10%).</pre><p>This time if we set <strong>maxUnavailble</strong> we are able to specify the minimum amount of pods that can be down during the rollout.</p><p><strong>Avoid this:</strong></p><p>What if I set <strong>maxUnavailable</strong> to 0 and the <strong>maxSurge</strong> to 0?</p><p>Well, this means that zero pods can be unavailable and that you cannot create more than 8 pods (remember <strong>maxSurge</strong> refers to the total pods allowed at once).</p><p>It can’t create extra pods(<strong>maxSurge</strong>=0) and it cant terminate a pod either(<strong>maxUnavailable</strong>=0) so this would make your deployment invalid!</p><p>Now that we got that out of the way. Let&#39;s try a <strong><em>working example</em></strong>.</p><p>Let&#39;s add a valid <strong>Deployment Rollout Strategy:</strong></p><pre>apiVersion: extensions/v1beta1<br>kind: Deployment<br>metadata:<br>  name: testing-rolling-updates<br>spec:<br><strong>  replicas: 8<br></strong>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx-container<br>        image: nginx<br><strong>      strategy:<br>        type: RollingUpdate<br>        rollingUpdate:<br>          maxSurge: 40%<br>          maxUnavailable: 4</strong></pre><p>This means we can have 140% of our specified replicas(<strong>maxSurge</strong>). <strong>maxUnavailable</strong> is set to 4 meaning we can have 4 pods down at once.</p><p>Here is what it would look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*lnW1nrr_qHlYXrn9TpY8uQ.png" /><figcaption>View of live updates occurring in a deployment.</figcaption></figure><p><a href="https://asciinema.org/a/EFb2e97xMNvn1mfKm2Lfrt9g3"><strong><em>Click here</em></strong></a> for the full recording.</p><p>You can see that we were able to increase the max amount of pods 140%(pending and running pods combined). While keeping the <strong>maxUnavaible</strong> pods at 4 or below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*NQQpP2LsEvU6SdkZIi5sdA.png" /></figure><p><strong>Boom!</strong></p><p>Now you have a new tool to help you ace the <strong>CKAD</strong>! Don’t forget about the little people when you do!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b434ba160093" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-ckad-exam-question-you-havent-seen-b434ba160093">The CKAD Exam Question you haven’t seen!</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K8s Network Policies Demystified and Simplified]]></title>
            <link>https://medium.com/swlh/k8s-network-policies-demystified-and-simplified-18f5ea9848e2?source=rss-5dc837edef50------2</link>
            <guid isPermaLink="false">https://medium.com/p/18f5ea9848e2</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubernetes-engine]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Isidro Hernandez]]></dc:creator>
            <pubDate>Fri, 01 May 2020 21:43:50 GMT</pubDate>
            <atom:updated>2020-05-02T18:47:40.783Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0SdlPrPylSJJ3FOq8RwKbQ.png" /></figure><p>A very important part of Kubernetes is how we are able to apply network rules in a dynamic way through the use of labels and selectors. Today I wanted to share with you how to easily implement these policies into your deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3Fou6ul9zIqujrzmFAwxQ.gif" /></figure><p>It’s easy to be lackadaisical about hardening our clusters but It&#39;s crucial to the survivability of the application. Understanding a NetworkPolicy is an amazing tool and its easy to use if you follow these tips ;)</p><p>When I think of a Firewall rule I think of three things:</p><p>Who, What, and Why.</p><h3><strong>Who</strong>:</h3><p>Let&#39;s define what are the resources we are trying to protect or expose.</p><h3>What:</h3><p>Decide what needs to be done. This can be blocking or allowing traffic on a port.</p><h3>Why:</h3><p>What is the reason for this rule? Understanding the purpose to a rule is more important than implementing it mindlessly.</p><h3>Scenario</h3><p>Our team wants to allow and deny traffic from parts of our corporate network and from our Pod resources inside our cluster. We have a collection of pods that require some ingress and egress traffic rules. Isolate pods in the default namespace with label role=db. We want to accept traffic on TCP port 6379 from cidr 172.17.0.0/16 with an exception of 172.17.1.0/24. We want to accept traffic from all pods belonging to the namespace project=frontend . For additional granularity, we will also allow traffic from pods with a label role=backend . We want to allow egress connections on the default namespace with the label role=db to cidr 10.0.0.0/24 on TCP port 5978</p><p>Did you get all that? It&#39;s complicated when you read a word problem like this. If we break it down by who, what, and why, this becomes an easier problem to deal with.</p><h3>Who</h3><p>Pods in the default namespace and labels of role=frontend for both ingress and egress traffic.</p><h3>What</h3><p>Ingress — Any Pod in a Namespace label of project=myproject <br>Ingress — Any Pod in the default namespace with label role=frontend <br>Ingress — IP addresses in the ranges 172.17.0.0–172.17.0.255 and 172.17.2.0–172.17.255.255 (ie, all of 172.17.0.0/16 except 172.17.1.0/24)</p><p>Egress — Allow connections from any pod in the default namespace with label role=db to CIDR 10.0.0.0/27 TCP port 5978</p><h3><strong>Why</strong></h3><ol><li>We need to allow pods labeled role=frontend to make connections with our backend database.</li><li>We need pods that are labeled role=frontend to have the ability to connect to each other.</li><li>We want to allow connections from specific CIDR blocks while making an exception for one block of addresses.</li></ol><h3>Boom!</h3><p>Now we have a better understanding of what we need to define in a manifest.</p><p>Let&#39;s get into the nitty-gritty!</p><p>Let us familiarize ourselves with our API specifications.</p><pre>kubectl explain networkpolicies<br>kubectl explain networkpolicies.spec. --recursive<br>kubectl explain networkpolicies.spec.ingress<br>kubectl explain networkpolicies.spec.egress</pre><p>Making a habit of checking these will make you a better Kubernetes developer ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmik7_V9S77iE_GoR-NJcw.gif" /></figure><p>Starting from the top to the bottom….</p><h4>Who: Define what pods we want this rule to apply to:</h4><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: test-network-policy<br>  namespace: default<br>spec:<br>  <strong>podSelector:<br>    matchLabels:<br>      role: db</strong></pre><h4>What: Define what types of policies we will use:</h4><pre>policyTypes:<br>  - Ingress<br>  - Egress</pre><h4>Define our ingress rules</h4><pre>ingress:<br>  - from:<br>    - ipBlock:<br>        cidr: 172.17.0.0/16<br>        except:<br>        - 172.17.1.0/24<br>    - namespaceSelector:<br>        matchLabels:<br>          project: myproject<br>    - podSelector:<br>        matchLabels:<br>          role: frontend<br>    ports:<br>    - protocol: TCP<br>      port: 6379</pre><p>….. how does this manifest piece match up with our API specs?</p><pre>kubectl explain networkpolicies.spec.ingress --recursive <br>***<br>FIELDS:<br>   <strong>from</strong> &lt;[]Object&gt;<br>      ipBlock &lt;Object&gt;<br>         cidr &lt;string&gt;<br>         except &lt;[]string&gt;<br>      namespaceSelector &lt;Object&gt;<br>         matchExpressions &lt;[]Object&gt;<br>            key &lt;string&gt;<br>            operator &lt;string&gt;<br>            values &lt;[]string&gt;<br>         matchLabels &lt;map[string]string&gt;<br>      podSelector &lt;Object&gt;<br>         matchExpressions &lt;[]Object&gt;<br>            key &lt;string&gt;<br>            operator &lt;string&gt;<br>            values &lt;[]string&gt;<br>         matchLabels &lt;map[string]string&gt;<br>   <strong>ports</strong> &lt;[]Object&gt;<br>      port &lt;string&gt;<br>      protocol &lt;string&gt;</pre><p>Notice that we will define a <strong>from</strong> object and a <strong>port</strong> object. Within these objects lies the opportunity to define the specific resources you want to declare.</p><p>A similar output is shown when you review our egress API Spec. Notice that here we need object <strong>to</strong> and <strong>ports</strong> as well.</p><pre>kubectl explain networkpolicies.spec.egress --recursive<br>***</pre><pre>FIELDS:<br>   <strong>ports</strong> &lt;[]Object&gt;<br>      port &lt;string&gt;<br>      protocol &lt;string&gt;<br>   <strong>to</strong> &lt;[]Object&gt;<br>      ipBlock &lt;Object&gt;<br>         cidr &lt;string&gt;<br>         except &lt;[]string&gt;<br>      namespaceSelector &lt;Object&gt;<br>         matchExpressions &lt;[]Object&gt;<br>            key &lt;string&gt;<br>            operator &lt;string&gt;<br>            values &lt;[]string&gt;<br>         matchLabels &lt;map[string]string&gt;<br>      podSelector &lt;Object&gt;<br>         matchExpressions &lt;[]Object&gt;<br>            key &lt;string&gt;<br>            operator &lt;string&gt;<br>            values &lt;[]string&gt;<br>         matchLabels &lt;map[string]string&gt;</pre><h4>Now we can tie it all together.</h4><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: test-network-policy<br>  namespace: default<br><strong>spec:<br>  podSelector:<br>    matchLabels:<br>      role: db</strong><br>  policyTypes:<br>  - Ingress<br>  - Egress<br>  <strong>ingress:<br>  - from:</strong><br>    - ipBlock:<br>        cidr: 172.17.0.0/16<br>        except:<br>        - 172.17.1.0/24<br>    - namespaceSelector:<br>        matchLabels:<br>          project: myproject<br>    - podSelector:<br>        matchLabels:<br>          role: frontend<br>    <strong>ports</strong>:<br>    - protocol: TCP<br>      port: 6379<br>  <strong>egress</strong>:<br>  - <strong>to</strong>:<br>    - ipBlock:<br>        cidr: 10.0.0.0/24<br>    <strong>ports</strong>:<br>    - protocol: TCP<br>      port: 5978</pre><p>Now we can create NetworkPolcies with confidence!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18f5ea9848e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/k8s-network-policies-demystified-and-simplified-18f5ea9848e2">K8s Network Policies Demystified and Simplified</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Kubernetes Developer Quick Guide to Tricky Manifests. Part 3: Mounting Secrets]]></title>
            <link>https://medium.com/@ihernandezjr/a-kubernetes-developer-quick-guide-to-tricky-manifests-part-3-mounting-secrets-eb7960151d88?source=rss-5dc837edef50------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb7960151d88</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Isidro Hernandez]]></dc:creator>
            <pubDate>Sun, 26 Apr 2020 03:51:08 GMT</pubDate>
            <atom:updated>2020-04-26T03:51:08.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gnl4zdgHbvsC-W56BuHBKw.png" /></figure><p>I think we started with a solid foundation covering service selectors and mounting volumes. Now we can dig into building and mounting secrets.</p><h4>How can pods access secrets?</h4><p>There are two ways a pod can interact with secrets.</p><ol><li>Environment Variables</li><li>Mount Files</li></ol><p>Let&#39;s start by creating a quick secret using kubectl</p><pre>kubectl create secret generic mysecret --from-literal=key222=value9999</pre><p>If you want to build from the manifest then use kubectl create -f file.yaml</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: mysecret<br>type: Opaque<br>data:<br>  key222: value9999</pre><p>Let&#39;s examine how to utilize this secret as an ENV variable in our pod</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: secret-test-pod<br>spec:<br>  containers:<br>    - name: test-container<br>      image: k8s.gcr.io/busybox<br>      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;env&quot; ]<br>      <strong>envFrom</strong>:<br>      - <strong>secretRef</strong>:<br>          <strong>name</strong>: mysecret<br>  restartPolicy: Never</pre><p>It was very simple to define the envFrom object. Notice that you did not have to specify the key from your secret. If you wish to define an ENV value you can add the key object. You can learn more by typing the following command.</p><pre>kubectl explain pod.spec.containers.envFrom</pre><p><strong>Using Secrets as Files on a Pod</strong></p><p>This is also very straight forward. Remember when we mounted volumes? This is similar to that. Remember our two steps? Great! If not go back to part 1.</p><p>Let&#39;s review the manifest:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: secret-test-pod<br>spec:<br>  <strong>volumes</strong>:<br>  - <strong>name</strong>: secret-volume<br>    <strong>secret</strong>:<br>      <strong>secretName</strong>: ssh-key-secret<br>  containers:<br>  - name: ssh-test-container<br>    image: mySshImage<br>    <strong>volumeMounts</strong>:<br>    - <strong>name</strong>: secret-volume<br>      <strong>readOnly</strong>: <strong>true</strong><br>      <strong>mountPath</strong>: &quot;/etc/secret-volume&quot;</pre><p>Step 1. Of mounting a volume is? Declaring a volume in pod.spec.volumes . This time instead of a PVC we will define an existing secret using pod.spec.volumes.secret.secretName . This will create a volume that our pod can access. Place the name of the existing secret here.</p><p>Step 2.</p><p>Mounting the Volume to the Pod is exactly the same. We will use pod.spec.containers.volumeMounts to mount our secret. We can use the name of the volume as our name and we will add readOnly: true . This will prevent someone from editing the secret file. mountPath will define our path we want to mount our secret.</p><p>Build and confirm your secret has mounted properly by running the following command.</p><pre>kubectl describe pod secret-test </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb7960151d88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Kubernetes Developer Quick Guide to Tricky Manifests. Part 2: Volume Mounts]]></title>
            <link>https://medium.com/@ihernandezjr/a-kubernetes-developer-quick-guide-to-tricky-manifests-part-2-volume-mounts-ac28a8fb9786?source=rss-5dc837edef50------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac28a8fb9786</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Isidro Hernandez]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 23:44:56 GMT</pubDate>
            <atom:updated>2020-04-25T23:44:56.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gnl4zdgHbvsC-W56BuHBKw.png" /></figure><p>In our second installment in this series, I wanted to dig into Kubernetes Volumes and how to mount them. Kubernetes allows for a vast selection of storage configurations and knowing the differences inside the manifest are integral. This time we will talk a bit more about the required YAML objects as well as the most common implementations of Volumes.</p><p>Traditionally in courses, they will explain a single k8s resource(pod, vol, svc…) and how to use its different features. Today I wanted to take a different approach and show you how to mount the most common objects as a volume to a pod.</p><h4>Volumes</h4><p>Let&#39;s review the definition from the API docs:</p><pre>On-disk files in a Container are ephemeral, which presents some problems for non-trivial applications when running in Containers. First, when a Container crashes, kubelet will restart it, but the files will be lost - the Container starts with a clean state. Second, when running Containers together in a Pod it is often necessary to share files between those Containers. The Kubernetes Volume abstraction solves both of these problems.</pre><p><strong>How can we mount a Persistent Volume Claim?</strong></p><p>Let us start by creating a PV and move on to mounting a PVC. We will create a PV and PVC using the manifests below. Notice the selector in our PVC. If it doesn&#39;t match the PV it will not bind to it. Thus making it useless.</p><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: task-pv-volume<br>  <strong>labels:<br>    type: local</strong><br>spec:<br>  storageClassName: manual<br>  capacity:<br>    storage: 10Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  hostPath:<br>    path: &quot;/mnt/data&quot;</pre><p>When you don’t specify a label selector in your PVC it will bind to any available PV. In this example, we are labeling our PV and using selector.matchLabels to bind them together. Make sure you understand you only need to specify a selector when you need to use a specific PV.</p><pre>Claims can specify a label selector to further filter the set of volumes. Only the volumes whose labels match the selector can be bound to the claim. The selector can consist of two fields:</pre><pre><strong>matchLabels</strong> - the volume must have a label with this value<br><strong>matchExpressions</strong> - a list of requirements made by specifying key, list of values, and operator that relates the key and values. Valid operators include In, NotIn, Exists, and DoesNotExist.</pre><p>Our PVC is pretty straight forward. Notice that we are defining other YAML objects here as well. Since kubectl create and kube run do not create these resources yet. I suggest using these examples from the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume">documentation page</a>.</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: myclaim<br>spec:<br>  accessModes:<br>    - ReadWriteOnce<br>  volumeMode: Filesystem<br>  resources:<br>    requests:<br>      storage: 8Gi<br>  storageClassName: slow<br>  <strong><em>selector:<br>    matchLabels:<br>      type: local</em></strong><br>    </pre><p>After you create these two resources you can view them using :</p><pre>kubectl get pv,pvc </pre><pre>Both should have a status of &quot;Bound&quot;</pre><h4>Boom!</h4><p>Now that we have a Volume we can use let&#39;s mount that shit to our pod.</p><p>There are always two things to remember when mounting a volume.</p><ol><li>Define the volume in pod.spec.</li><li>Define the mount point in the container at pod.spec.container.volumeMounts</li></ol><p>Let&#39;s take a look at the manifest for this <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-pod">configuration</a>.</p><pre>pods/storage/pv-pod.yaml</pre><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: task-pv-pod<br>spec:<br>  <strong>volumes</strong>:<br>    - <strong>name</strong>: task-pv-storage<br>      <strong>persistentVolumeClaim</strong>:<br>        <strong>claimName</strong>: task-pv-claim<br>  containers:<br>    - name: task-pv-container<br>      image: nginx<br>      ports:<br>        - containerPort: 80<br>          name: &quot;http-server&quot;<br>      <strong>volumeMounts</strong>:<br>        - <strong>mountPath</strong>: &quot;/usr/share/nginx/html&quot;<br>          <strong>name</strong>: task-pv-storage</pre><p>Notice the required yaml objects for defining a PVC volume in a pod.</p><pre>pod.spec.volumes</pre><ol><li><strong>- name</strong>: task-pv-storage</li><li><strong>persistentVolumeClaim</strong> &lt;object&gt;</li><li><strong>claimName: </strong>task-pv-claim</li></ol><p>Now let&#39;s look at how we mounted the volume to the container. Notice the required object values.</p><pre>pod.spec.container.volumeMounts</pre><ol><li>- <strong>mountPath</strong>: &quot;/usr/share/nginx/html&quot;</li><li><strong>name</strong>: task-pv-storage</li></ol><p>This was relatively easy. So just remember, first you define a volume in a pod then you can define mounting the volume to a container. Two steps should be easy to remember.</p><p><strong>How can we mount a folder from a Node to our Pods?</strong></p><p>This is a really cool trick to get a shared folder from the Node to the Pod. Lets review a manifest and remember the two steps from our last section.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: test-pd<br>spec:<br>  containers:<br>  - image: k8s.gcr.io/test-webserver<br>    name: test-container<br>    <strong>volumeMounts</strong>:<br>    - mountPath: /test-pd<br>      name: test-volume<br>  <strong>volumes</strong>:<br>  - <strong>name</strong>: test-volume<br>    <strong>hostPath</strong>:<br>      # directory location on host<br>      <strong>path</strong>: /data<br>      # this field is optional<br>      <strong>type</strong>: Directory</pre><p>This time you can see the pod.spec.containers.volumeMounts section is pretty much the same.</p><p>If you take a look at the pod.spec.volumes.hostPathsection. We can see that we are defining a hostPath object. We also define the path on our Node. Then we specify the type. We are using a directory here but you <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath">can use other types.</a></p><p>That is enough to get is started with volumes. Let’s review how we can use ConfigMaps and Secrets in the next post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac28a8fb9786" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Kubernetes Developer Quick Guide to Tricky Manifests. Part 1: Selectors and Labels.]]></title>
            <link>https://medium.com/swlh/a-kubernetes-developer-quick-guide-to-tricky-manifests-part-1-selectors-and-labels-b82060bfd840?source=rss-5dc837edef50------2</link>
            <guid isPermaLink="false">https://medium.com/p/b82060bfd840</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gke]]></category>
            <dc:creator><![CDATA[Isidro Hernandez]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 08:37:02 GMT</pubDate>
            <atom:updated>2020-04-28T06:44:00.845Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Kubernetes Developer Quick Guide to Tricky Manifests. Part 1: Selectors and Labels</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gnl4zdgHbvsC-W56BuHBKw.png" /></figure><p>While working with Kubernetes you were undoubtedly impressed by the flexibility and scalability of this orchestration platform. You probably by now created a few pods, services, and tinkered with Nginx enough to feel dangerous.</p><p>As I was preparing for my CKAD exam I spent a lot of time comparing manifests and noticing the subtle differences for each resource. I’m not going to cover all of the nuances of the API or kubectl. What I will cover are the core resource manifests and their quirks.</p><p>Have you ever wondered why you can’t mount a volume? You spent hundreds of seconds reviewing the error message and another hundred seconds to look up the API documentation and update your YAML file. I hope to simplify those hiccups for you and me both.</p><h4><strong>How do deployments select other resources(pods or replica sets)?</strong></h4><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br> name: nginx-deployment<br> labels: <strong># the deployment itself has a label here</strong><br>   app: nginx<br>spec:<br> replicas: 3<br> selector: <strong># this selector will apply to any pod with the matching</strong> labels.<br>  matchLabels:<br>    app: nginx<br> template: <strong># this is starting to configure the pods within</strong><br>   metadata: <strong># they have to have their own labels defined here.</strong> <strong><br>     </strong>labels:<br>        app: nginx<br> spec:<br>   containers:<br>   — name: nginx<br>     image: nginx:1.14.2<br>     ports:<br>     — containerPort: 80</pre><p><strong>Selector</strong></p><pre><strong>deployment.spec.selector.matchLabels</strong></pre><pre>Label selector for pods. Existing ReplicaSets whose pods are selected by this will be the ones affected by this deployment.</pre><p>This defines the label selector for any pods or ReplicaSets with the matching labels.</p><p>If you need to tag your pods within your Deployment then you would do that here(within yaml manifest):</p><pre><strong>deployment.spec.template.metadata.labels</strong></pre><h4>How do you apply a service resource to a deployment, pod, or ReplicaSet?</h4><pre>apiVersion: v1<br>kind: Service<br>metadata:<br> name: my-service<br>spec:<br> <strong>selector:</strong>     # Notice that here we only use &#39;selector&#39;<br>   app: MyApp<br> ports:<br> — protocol: TCP<br>   port: 80<br>   targetPort: 9376</pre><p>It&#39;s important to notice that when creating a service object that other resources are going to consume that the label declaration is a bit different than in Deployments. Here we will only require that we define the labels using:</p><pre><strong>service.spec.selector</strong></pre><p>In this example, the <strong>app=MyApp</strong> label will be used as a selector. It&#39;s easy to get these first two resource objects confused.</p><h4>How can we label a pod so that Selectors from other object resources can find it?</h4><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: label-demo<br>  <strong>labels</strong>: # this is very is to do. labels are nested under metadata. <br>    environment: production<br>    app: nginx<br>spec:<br>  containers:<br>  - name: nginx<br>    image: nginx:1.14.2<br>    ports:<br>    - containerPort: 80</pre><p>A simple label can be defined inside:</p><pre><strong>pod.metadata.labels</strong></pre><p>To add a quick label with kubectl:</p><pre><strong>kubectl label pod $PODNAME key=value</strong></pre><p>Test this with:</p><pre><strong>kubectl get pods -l key=value</strong></pre><h4>How can we apply a NetworkPolicy to a resource?</h4><p>A NetworkPolicy can be hard to remember. They aren&#39;t using the same rules we observed above. Let&#39;s take a look at the API reference using:</p><pre><strong>$ kubectl explain networkpolicy.spec</strong></pre><pre><strong>podSelector &lt;Object&gt; -required-</strong><br>Selects the pods to which this NetworkPolicy object applies. The array of ingress rules is applied to any pods selected by this field. Multiple network policies can select the same set of pods. In this case, the ingress rules for each are combined additively. This field is NOT optional and follows standard label selector semantics. An empty podSelector matches all pods in this namespace.</pre><p>We find that in order to implement a NetworkPolicy we will need to define a PodSelector YAML object. Let&#39;s see what a sample YAML manifest looks like for this resource:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: NetworkPolicy<br>metadata:<br>  name: test-network-policy<br>  namespace: default<br>spec:<br><strong>  podSelector:<br></strong>    matchLabels:<br>      role: db</pre><p>Now we can see that this manifest is asking for something slightly different with the same principles in mind. We now know where to define the selector labels in this manifest:</p><pre><strong>networkpolicy.spec.podSelector.matchLabels</strong></pre><p>This concludes Part 1.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b82060bfd840" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/a-kubernetes-developer-quick-guide-to-tricky-manifests-part-1-selectors-and-labels-b82060bfd840">A Kubernetes Developer Quick Guide to Tricky Manifests. Part 1: Selectors and Labels.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>