<?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 Harshal Kathar on Medium]]></title>
        <description><![CDATA[Stories by Harshal Kathar on Medium]]></description>
        <link>https://medium.com/@katharharshal1?source=rss-88fc6c498f63------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*V1xQZB3hMsM9KwupdJUfVA.jpeg</url>
            <title>Stories by Harshal Kathar on Medium</title>
            <link>https://medium.com/@katharharshal1?source=rss-88fc6c498f63------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:44:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@katharharshal1/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[Deploy Spring boot application into Google Kubernetes Engine (GKE) using Argo CD GitOps]]></title>
            <link>https://katharharshal1.medium.com/deploy-spring-boot-application-into-google-kubernetes-engine-gke-using-argo-cd-gitops-2d774bf270ba?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d774bf270ba</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gke]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[argo-cd]]></category>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Tue, 01 Feb 2022 09:06:42 GMT</pubDate>
            <atom:updated>2022-02-01T09:06:42.608Z</atom:updated>
            <content:encoded><![CDATA[<h3>GitOps Flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ql2ng1eBxpR96prNaA6DCA.png" /><figcaption><strong>GitOps Flow</strong></figcaption></figure><p>GitOps Flow:</p><ol><li>Git: developers push their changes to the git.</li><li>Jenkins: Using the CICD server(Jenkins) we pulled the code from git, and compile the code and create a docker image.</li><li>GCR: Newly created docker image we push to the GCP GCR.</li><li>Manifest Update: Jenkins Job update the git manifest(deployment.yaml) with newly created image.</li><li>ArgoCD is a CD tool used to Deploy Application into Kubernetes clusters, based upon the manifests file within a Git repository.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/0*n6pKvmWQ-ac3efrE" /><figcaption>Gitops</figcaption></figure><h3>Prerequisites:</h3><ol><li>Set up Jenkins server and install docker on it.</li><li>Google Kubernetes Engine (GKE)</li><li>Install gcloud sdk also on Jenkins server.</li></ol><p>Note: Verify that you have the required permissions. You must have the Storage Admin role (roles/storage.admin)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*xWaLHsm2RzgomuGpJAVLYQ.png" /><figcaption>gcloud init</figcaption></figure><p>4. Install required Jenkins Plugins</p><ol><li>Google OAuth Credentials</li><li>Docker Pipeline</li><li>Google Container Registry Auth</li></ol><h3>Getting started:</h3><p><strong>1.Create a Service account in GCP.</strong></p><p>Jenkins want a GCR access to push the images to GCR Repo, so for these purpose we are now creating Service account and give a Storage admin permission.</p><ol><li>Go to the IAM &amp; Admin Service, and left side you see the Service Accounts -&gt; Click on Create Service Account.</li></ol><p>2. Create a Service account and attached below role.</p><p>Attach Roles: Storage -&gt;Storage Admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*Y1v1KeTaMJPZ_z_r7xu-kg.jpeg" /></figure><p>3. Create Service Account key in json format. Downloaded key keep it safe we will be requiring in further configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*3_usajyZ7iOecHMLYq6a9A.png" /></figure><h3>2.Creating Jenkins prerequisites.</h3><p><strong>step1: maven3 installation on Jenkins server:</strong></p><ol><li>We build and deploy the spring boot application using maven so we install or add maven packages using Jenkins global tool configuration.</li></ol><p>path: Jenkins -&gt; managed Jenkins -&gt; global tool configuration -&gt; maven</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*mEYm3Dwq-pa8_tot.jpeg" /></figure><p><strong>2.Add GCR service account json auth key as a credentials in Jenkins.</strong></p><p>Jenkins -&gt; Credentials -&gt; Global Credentials -&gt; Add Credentials</p><p>Select kind : Google Service Account from private key</p><p>Provide Project Name(which can be any thing) and click on JSON key .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*efDmf1tuPk0zcdL5-EMtMw.png" /></figure><p><strong>3. Add github credentials to the jenkins</strong></p><p>Kind: username and password</p><p>Username: git username</p><p>Password: git token</p><p>note: Don’t use github password, create new token and use it as a password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2RJs3E2F8mztAD_qtC4g6g.png" /><figcaption>github credentials set</figcaption></figure><p><strong>Note: Add Jenkins user to the docker group so you can execute Docker commands without using sudo.</strong></p><pre><br>sudo usermod -a -G docker jenkins</pre><p>login to jenkins user and run below comments</p><pre>1. su - jenkins<br>2.docker pull busybox<br>3.docker tag busybox gcr.io/&lt;my-projectid&gt;/busybox<br>4.docker push gcr.io/&lt;my-projectid&gt;/busybox</pre><p>if you got the permission issue like below.</p><p>unauthorized: You don’t have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: <a href="https://cloud.google.com/container-registry/docs/advanced-authentication">https://cloud.google.com/container-registry/docs/advanced-authentication</a></p><pre>run below comment using sudo user to resolve the permission issue.</pre><pre><strong>gcloud auth configure-docker</strong></pre><h3><strong>Install ArgoCD.</strong></h3><p><a href="https://argo-cd.readthedocs.io/en/stable/getting_started/">Getting Started - Argo CD - Declarative GitOps CD for Kubernetes</a></p><pre>note: default username is admin</pre><pre>You get the password by typing</pre><pre>kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=&quot;{.data.password}&quot; | base64 -d</pre><p>1.Create a new application on argocd</p><p>Application name: give microservice name</p><p>Project: you can create new or use default one</p><p>Sync: Automatic</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0xuQWCD1Y7XcRvyB8sD1Q.png" /><figcaption>Argocd</figcaption></figure><p>2.Connect your application repo to Argo CD by setting repository url to the github repo url, leave revision as HEAD, and set the path to Application manifest file.</p><p>note: if manifest file present in current directory no folder structure then use “./”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pBRBPr6qKKhOH4kf0sbfjg.png" /></figure><p>3. Set cluster URL to <a href="https://kubernetes.default.svc/">https://kubernetes.default.svc</a> (or in-cluster for cluster name) and namespace to default:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*VDVTL3zTrdg5nEVRHoiRYQ.png" /></figure><p>4. After filling out the information above, click <strong>Create</strong> at the top of the UI to create the application</p><h3>Jenkins CICD Pipeline:</h3><ol><li>Create a Jenkins job, of type pipeline.</li></ol><p>name: spring-boot-cicd</p><p>type: pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYqpSfzi2DC0gEpUByux7w.png" /><figcaption>jenkinsjob</figcaption></figure><p>Add Jenkins file:</p><p>1. Go to pipeline(job) -&gt; configure</p><p>2. In the pipeline session select pipeline script.</p><p>3. Write a Jenkins file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAnKuMXbTyHW_rFbCMvdJA.png" /></figure><p>Jenkinsfile</p><p>Use below jenkins file.</p><p><a href="https://github.com/harshalkathar/myfirstapp/blob/master/Jenkinsfile">myfirstapp/Jenkinsfile at master · harshalkathar/myfirstapp</a></p><p>Jenkinsfile overview:</p><p><strong>Stage 1: git clone happened here, Jenkins pull the source code in this stage.</strong></p><ol><li>I have written a simple spring boot code and I have the src, pom.xml, docker file, Kubernetes manifest file. we clone all these files here using Jenkins CI.</li></ol><p><strong>stage 2: maven compile the code and create a package.</strong></p><p>we install maven using Jenkins global tool configuration, now we install the maven packages that we need to compile our code and as an end result we got a jar file.</p><pre><strong>note: def mvnHome = tool name: ‘maven’: the tool name must same as the name given by you at the time of maven installation using Jenkins global tool configuration.</strong></pre><p><strong>stage 3: building Docker images with the help of Dockerfile.</strong></p><p>In these step we are building docker image also creating the GCR repo, if repo not created before and tag the docker image with gcp project id and repo name.</p><pre>app = docker.build(&quot;&lt;gcp-project-id&gt;/springboot&quot;) <br>   </pre><p><strong>stage 4: pushing the docker image to GCP GCR.</strong></p><p>Note: here “gcp” is a gcp service account credentials id that we store into the Jenkins for GCR access.</p><p>gcr:&lt;Jenkins credentials id&gt;</p><pre> docker.withRegistry(&#39;https://gcr.io&#39;, &#39;gcr:gcp&#39;)</pre><p><strong>stage 5: Update Git repo with latest image.</strong></p><p>In these stage Jenkins Job update the git manifest(deployment.yaml) with newly created image.</p><h3>using Jenkins CICD we successfully build our sample spring boot application.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_p6qLrw1o6NkFpalYYBXA.png" /></figure><h3><strong>Onces image is created and Jenkins Commit the changes to the git, argocd auto sync these changes and deploy the application to the GKE cluster using manifest file.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02yC_DrAZ2tMX1QO7ifXnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YWc9l4Q9Sw97orHYqPFfkA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QiGivcZNd6SJGnpn8j2MMw.jpeg" /></figure><p>We expose our application using a load balancer on port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*dTmRexWuzpS8GkmR_6rCUg.png" /></figure><h3>Thank you, if you have any doubt reach out to me</h3><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d774bf270ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Spring boot application into AWS EKS using Jenkins CICD]]></title>
            <link>https://katharharshal1.medium.com/deploy-spring-boot-application-into-aws-eks-using-jenkins-cicd-2ced0e0d894c?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ced0e0d894c</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 14:39:26 GMT</pubDate>
            <atom:updated>2021-07-06T14:39:26.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*RDP9pt4F-XFDcKxDUXxwYA.png" /><figcaption><strong>CICD Flow</strong></figcaption></figure><p>CICD Flow:</p><ol><li>Git: developers push their change to the git.</li><li>Jenkins: Using the CICD server(Jenkins) we pulled the code from git, and compile the code and create a docker image.</li><li>ECR: Newly created docker image we push to the AWS ECR repo.</li><li>EKS: Deploy the docker image into the EKS using k8s deployment YAML.</li></ol><h3>Prerequisites:</h3><ol><li>Set up Jenkins server and install docker on it.</li><li>Kubernetes(EKS) cluster up and running.</li></ol><p><a href="https://katharharshal1.medium.com/deploying-a-kubernetes-cluster-with-amazon-eks-ae9f4ff18f77">Deploying a Kubernetes Cluster with Amazon EKS | by Harshal Kathar | Medium</a></p><p>3. Install below Jenkins plugins:</p><p>1. Amazon ECR plugin</p><p>2. Docker Pipeline</p><h3>Getting started:</h3><h3><strong>1: Create a repository for storing the docker images</strong></h3><p>here we create an aws ecr repo for storing the docker images.</p><p>Path: AWS -&gt;Services -&gt; ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*onEtx3SGy8gX7meKTI4Iww.png" /><figcaption>ECR Repo</figcaption></figure><h3><strong>2.Creating Jenkins prerequisites.</strong></h3><p><strong>step1: maven3 installation on Jenkins server:</strong></p><ol><li>We build and deploy the spring boot application using maven so we install or add maven packages using Jenkins global tool configuration.</li></ol><p>path: Jenkins -&gt; managed Jenkins -&gt; global tool configuration -&gt; maven</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IIcOiPOxZqnYq65Ycopvvg.jpeg" /></figure><p><strong>Step 2. Add Aws credentials to Jenkins.</strong></p><p>Enter the Access ID and Secret Access Key for the AWS user that has access to the ECR repository.</p><p>Path: managed Jenkins -&gt; managed credentials -&gt; global credentials -&gt; Add credentials</p><p>select kind= AWS Credentials</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQj7_Zs_Ii6HleL3kDeHxg.jpeg" /></figure><p><strong>3. Set up Jenkins server to deploy the application on EKS Cluster.</strong></p><pre>Steps:<br>Install kubectl on a Jenkins server.<br>2. switched to Jenkins user: sudo -i -u jenkins<br>3. create a .kube folder into the Jenkins home directory<br> : cd ~<br> : mkdir .kube<br>4. create a config file and copy the master kube config file content.<br>5.Check Jenkins user able to access pod, deployment using kubectl comments.</pre><p><strong>Note: Add the ec2-user, Jenkins user to the docker group so you can execute Docker commands without using sudo.</strong></p><pre>sudo usermod -a -G docker ec2-user</pre><pre>sudo usermod -a -G docker jenkins</pre><h3>Jenkins CICD Pipeline:</h3><ol><li>Create a Jenkins job, of type pipeline.</li></ol><p>name: spring-boot-cicd</p><p>type: pipeline</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*shWj0wiVT-zv9lFjBMXKLg.jpeg" /><figcaption>job</figcaption></figure><p>Add Jenkins file:</p><p>1. Go to pipeline(job) -&gt; configure</p><p>2. In the pipeline session select pipeline script.</p><p>3. Write a Jenkins file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RSMSAHM-kUsNuYknW1SmHA.jpeg" /></figure><p>Jenkinsfile:</p><pre>node {<br>  def image<br>   //1//  stage (&#39;checkout&#39;) {<br>        checkout([$class: &#39;GitSCM&#39;, branches: [[name: &#39;*/master&#39;]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: &#39;&#39;, url: &#39;<a href="https://github.com/harshalkathar/myfirstapp.git&#39;">https://github.com/harshalkathar/myfirstapp.git&#39;</a>]]])      <br>        }<br>   <br> //2//   stage (&#39;Build&#39;) {<br>         def mvnHome = tool name: &#39;maven&#39;, type: &#39;maven&#39;<br>         def mvnCMD = &quot;${mvnHome}/bin/mvn &quot;<br>         sh &quot;${mvnCMD} clean package&quot;           <br>        }<br>       <br>       <br>   //3// stage (&#39;Docker Build&#39;) {<br>         <br>            docker.build(&#39;springboot&#39;)<br>        }<br> //4// stage (&#39;Docker push&#39;)<br>    docker.withRegistry(&#39;<a href="https://989896714915.dkr.ecr.ap-south-1.amazonaws.com&/#39;">https://&lt;accountno&gt;.dkr.ecr.ap-south-1.amazonaws.com</a><a href="https://989896714915.dkr.ecr.ap-south-1.amazonaws.com&/#39;">&#39;</a>, &#39;ecr:ap-south-1:test-ecr&#39;) {<br>    docker.image(&#39;springboot&#39;).push(&#39;latest&#39;)<br>        }<br>  <br> //5// stage (&#39;K8S Deploy&#39;){<br>                    sh &#39;kubectl apply -f spring-boot.yaml&#39;<br>      } <br>       }</pre><p>Jenkinsfile overview:</p><p><strong>Stage 1: git clone happened here, Jenkins pull the source code in this stage.</strong></p><ol><li>I have written a simple spring boot code and I have the src, pom.xml, docker file, Kubernetes manifest file. we clone all these files here using Jenkins CI.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*vDUMJ4sWGYmpDsDZ5sJ-Dw.png" /><figcaption>git</figcaption></figure><p><strong>stage 2: maven compile the code and create a package.</strong></p><p>we install maven using Jenkins global tool configuration, now we install the maven packages that we need to compile our code and as an end result we got a jar file.</p><pre><strong>note: def mvnHome = tool name: ‘maven’: the tool name must same as the name given by you at the time of maven installation using Jenkins global tool configuration.</strong></pre><p><strong>stage 3: building Docker images with the help of Dockerfile.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*y9sH_1lPDdOrhwzIp6R6dA.png" /><figcaption>Dockerfile</figcaption></figure><pre>Note: docker.build(‘springboot’) : springboot is a ECR repo name.</pre><p><strong>stage 4: pushing the docker image to AWS ECR.</strong></p><pre>note: docker.withRegistry(‘<a href="https://989896714915.dkr.ecr.ap-south-1.amazonaws.com&/#39;">https://&lt;accountno&gt;.dkr.ecr.ap-south-1.amazonaws.com</a><a href="https://989896714915.dkr.ecr.ap-south-1.amazonaws.com&/#39;">’</a>, <strong>‘ecr:ap-south-1:test-ecr’</strong>) : here test-ecr is a aws credentials id that we store into the jenkins.</pre><p><strong>stage 5: Deploy the application using the k8s deployment YAML file. (CD)</strong></p><p>In my git repo, I also write 1 Kubernetes manifest file using this manifest file Jenkins does the deployment here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*gQah_dKSChQ_yF0_FsBrgA.png" /></figure><h3>using Jenkins CICD we successfully deploy our sample spring boot application to the Kubernetes.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YChK4CkAoTOqJbPzI522g.jpeg" /></figure><p>We expose our application using a load balancer on port 8080.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*ZcoQRu1pt4LqPTVH3OnT1A.jpeg" /></figure><h3>Thank you, if you have any doubt reach out to me</h3><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ced0e0d894c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backup And Restore EKS Kubernetes Using Velero.]]></title>
            <link>https://katharharshal1.medium.com/backup-and-restore-eks-kubernetes-using-velero-32b11cb55b81?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/32b11cb55b81</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[velero]]></category>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 10:47:09 GMT</pubDate>
            <atom:updated>2021-01-23T11:05:32.555Z</atom:updated>
            <content:encoded><![CDATA[<h3>Backup and Restore EKS Kubernetes Using Velero.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*y6FR7FH-vt--1uTpTpms7Q.png" /></figure><p>Velero is an open-source tool that helps automate the backup and restore of Kubernetes clusters, including any application and its data.</p><p>Velero lets you backup your entire cluster or namespace(s) or filter objects by using labels. Velero helps with migrating your on-prem Kubernetes workloads to the cloud, cluster upgrades, and disaster recovery.</p><p>Velero enables the following use cases:</p><ul><li>Disaster recovery — backup of the cluster and restore in case of a disaster.</li><li>Application migration — migrate an application along with its data from one cluster to another.</li><li>Application cloning — replicating production environments for testing and debugging.</li></ul><p>In this module, you will learn the below things:</p><p>1.how to backup and restore an EKS cluster using Velero.</p><p>2. how to backup and restore data on 2 different EKS Cluster.</p><p>3. how to backup and restore the data at a particular time(Scheduled backup and restore)</p><h3><strong>Let’s start:</strong></h3><p><strong>Prerequisites</strong></p><ol><li>AWS CLI needs to be configured in the machine where you execute Velero commands.</li><li>Kubectl needs to be configured with the EKS cluster where you need to take the backup.</li></ol><p><a href="https://katharharshal1.medium.com/deploying-a-kubernetes-cluster-with-amazon-eks-ae9f4ff18f77">Deploying a Kubernetes Cluster with Amazon EKS</a></p><h3>1. CREATE S3 BUCKET AND IAM USER FOR VELERO</h3><ol><li>Create the S3 bucket using AWS console.</li></ol><p>go to AWS -&gt; S3-&gt; create bucket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*qbCJAAO7pXgMLBPW4TtdYw.png" /></figure><p>2. Create an IAM user.</p><p>go to AWS -&gt; IAM Console -&gt; add user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*a5by5YdHYCZXi7hsdOTz9w.png" /></figure><p>3. Add the below permission to the user.</p><p>replace ${BUCKET} with S3 bucket name which we created for velero.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;ec2:DescribeVolumes&quot;,<br>                &quot;ec2:DescribeSnapshots&quot;,<br>                &quot;ec2:CreateTags&quot;,<br>                &quot;ec2:CreateVolume&quot;,<br>                &quot;ec2:CreateSnapshot&quot;,<br>                &quot;ec2:DeleteSnapshot&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;s3:GetObject&quot;,<br>                &quot;s3:DeleteObject&quot;,<br>                &quot;s3:PutObject&quot;,<br>                &quot;s3:AbortMultipartUpload&quot;,<br>                &quot;s3:ListMultipartUploadParts&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:s3:::${VELERO_BUCKET}/*&quot;<br>            ]<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;s3:ListBucket&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:s3:::${VELERO_BUCKET}&quot;<br>            ]<br>        }<br>    ]<br>}</pre><p>4. Add user credentials to the server.</p><p>using below comment</p><pre>aws configure</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*SHY9he3ivbC3FItiK0etuQ.png" /></figure><h3>2. INSTALL VELERO <strong>Client</strong></h3><p>Install Velero binary</p><pre>wget <a href="https://github.com/vmware-tanzu/velero/releases/download/v1.3.2/velero-v1.3.2-linux-amd64.tar.gz">https://github.com/vmware-tanzu/velero/releases/download/v1.3.2/velero-v1.3.2-linux-amd64.tar.gz</a></pre><p>Extract the tarball:</p><pre>tar -xvf velero-v1.3.2-linux-amd64.tar.gz -C /tmp</pre><p>Move the extracted velero binary to /usr/local/bin</p><pre>sudo mv /tmp/velero-v1.3.2-linux-amd64/velero /usr/local/bin</pre><p>Verify installation</p><pre>velero version</pre><p>output:</p><pre>Client:         Version: v1.3.2         Git commit: 55a9914a3e4719fb1578529c45430a8c11c28145 &lt;error getting server version: the server could not find the requested resource (post serverstatusrequests.velero.io)&gt;</pre><p>if you got the velero not found message then set a below path variable for velero.</p><p>e.x: export PATH=$PATH:/usr/local/bin</p><h3>3. Install Velero on EKS</h3><pre>velero install \<br>    --provider aws \<br>    --plugins velero/velero-plugin-for-aws:v1.0.1 \<br>    --bucket &lt;bucketname&gt;\<br>    --backup-location-config region=&lt;region&gt; \<br>    --snapshot-location-config region=&lt;region&gt; \<br>    --secret-file /root/.aws/credentials</pre><p>replace your bucket name, region, and credentials path in the command.</p><p>E.X:</p><pre>velero install \<br>    --provider aws \<br>    --plugins velero/velero-plugin-for-aws:v1.0.1 \<br>    --bucket velero-backup-harshal \<br>    --backup-location-config region=us-east-1 \<br>    --snapshot-location-config region=us-east-1 \<br>    --secret-file /root/.aws/credentials</pre><p>Inspect the resources created</p><pre>kubectl get all -n velero</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*0qumlMLBzSP-HzI2LFBVIQ.png" /></figure><h3>4. DEPLOY TEST APPLICATION</h3><p>Create namespace and deploy the application</p><pre>kubectl create namespace &lt;namespacename&gt;</pre><pre>kubectl create namespace harshal</pre><p>Deploy 2 sample applications in the harshal namespace.</p><pre>kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0 -n harshal</pre><pre>kubectl create deployment nginx --image=nginx -n harshal</pre><p>Verify deployment</p><pre>kubectl get deployments -n harshal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*0QSc-uD4kxTeyHKPS5jHKA.png" /></figure><h3>5. BACKUP AND RESTORE</h3><p>Let’s back up the harshal namespace using velero</p><p><strong>backup:</strong></p><pre>velero backup create &lt;backupname&gt; --include-namespaces &lt;namespacename&gt;</pre><pre>velero backup create test1 --include-namespaces harshal</pre><p>Check the status of backup</p><pre>velero backup describe &lt;backupname&gt;</pre><p>Check-in S3 bucket :</p><p>backup is stored in the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjzjBwaeQDQewazy8hIJPQ.png" /></figure><p>Let’s delete the ‘harshal’ namespace to simulate a disaster</p><pre>kubectl delete namespace harshal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*_YMBStv_oqTwtTaDc-amdA.png" /></figure><p>Restore harshal namespace</p><p><strong>restore:</strong></p><p>Run the velero restore command from the backup created. It may take a couple of minutes to restore the namespace.</p><pre>velero restore create --from-backup &lt;backupname&gt;</pre><pre>velero restore create --from-backup test1</pre><p>Verify if deployments, replica sets, services, and pods are restored.</p><p>In the below image you see, harshal namespace is newly created and restored using velero, and all old deployment, pods, svc also restored back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*jGn_Zi19JEwJXNBBJuwzpg.png" /></figure><h3>Take a backup on ClusterA and restore it to the clusterB<strong>.</strong></h3><ol><li>Install the velero on both the clusters: clusterA(backup),clusterB(restore)</li><li>Make sure both the cluster points to the same S3 bucket.</li></ol><p>E.X:</p><p>1.At ClusterA:</p><p>we using the below cmd to install velero on eks.</p><pre>velero install \<br>    --provider aws \<br>    --plugins velero/velero-plugin-for-aws:v1.0.1 \<br>    --bucket &lt;bucketname&gt;\<br>    --backup-location-config region=&lt;region&gt; \<br>    --snapshot-location-config region=&lt;region&gt; \<br>    --secret-file /root/.aws/credentials</pre><p>2. at ClusterB:</p><p>for velero install on eks used the same comment which clusterA used.</p><p>here we can use different user credentials also, <strong>but the I.M.P thing here is both the cluster point to the same S3 bucket.</strong></p><pre>velero install \<br>    --provider aws \<br>    --plugins velero/velero-plugin-for-aws:v1.0.1 \<br>    --bucket &lt;bucketname&gt;\<br>    --backup-location-config region=&lt;region&gt; \<br>    --snapshot-location-config region=&lt;region&gt; \<br>    --secret-file /root/.aws/credentials</pre><p>3. Test</p><ol><li>I created a 2 new namespace(demo,k8s) at cluster A and deployed the same test application on it.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*Gm3Q7xbY-UWDQ6V2XHP8Dw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*BZEhghJ_DVHTQZ9ybtsUzg.png" /></figure><p>2. Let’s back up the complete ClusterA.</p><pre>velero backup create &lt;BACKUP_NAME&gt;</pre><pre>velero backup create clusterbackup1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DB8rUJdw348OUXYD_7a30Q.png" /></figure><p>3. login to the ClusterB and restore the Cluster A backup on it.</p><pre>velero restore create --from-backup &lt;backupname&gt;</pre><pre>velero restore create --from-backup clusterbackup1</pre><p>In the below image we see backup is restored successfully and we got all the namespace and deployment, pod, svc on clusterB which are running at ClusterA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rnq2zIr-hA8YgLnUAjaOvw.png" /><figcaption>ns creation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*SFgpP8Fp8q3CKhwtOrv6RA.png" /></figure><h3><strong>Here are some useful commands for velero :</strong></h3><h3>Backup:</h3><pre><em># Create a backup every 6 hours with the @every notation</em><br>velero schedule create &lt;SCHEDULE_NAME&gt; --schedule=&quot;@every 6h&quot;<br><br><em># Create a daily backup of the namespace</em><br>velero schedule create &lt;SCHEDULE_NAME&gt; --schedule=&quot;@every 24h&quot; --include-namespaces &lt;namspacename&gt;<br><br><em># Create a weekly backup, each living for 90 days (2160 hours)</em><br>velero schedule create &lt;SCHEDULE_NAME&gt; --schedule=&quot;@every 168h&quot; --ttl 2160h0m0s     <br>##default TTL time is 720h</pre><pre><em># Create a backup including the test and default namespaces</em><br>velero backup create backup --include-namespaces test,default<br><br><em># Create a backup excluding the kube-system and default namespaces</em><br>velero backup create backup --exclude-namespaces kube-system,default</pre><pre># To backup entire cluster<br>velero backup create &lt;BACKUPNAME&gt;</pre><pre>#To backup namespace in a cluster<br>velero backup create &lt;BACKUPNAME&gt; --include-namespaces &lt;NAMESPACENAME&gt;</pre><h3>Restore:</h3><pre>#Manual Restore<br>velero restore create --from-backup &lt;backupname&gt;</pre><pre>#Scheduled Backup<br>velero restore create &lt;RESTORE_NAME&gt; --from-schedule &lt;SCHEDULE_NAME&gt;</pre><pre><em># Create a restore including the test and default namespaces</em><br>velero restore create --from-backup backup --include-namespaces nginx,default<br><br><em># Create a restore excluding the kube-system and default namespaces</em><br>velero restore create --from-backup backup --exclude-namespaces kube-system,default</pre><pre>#Retrieve restore logs<br>velero restore logs &lt;RESTORE_NAME&gt;</pre><h3>Thank you, if you have any doubt reach out to me</h3><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32b11cb55b81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Nginx Ingress Controller on Kubernetes Cluster.]]></title>
            <link>https://katharharshal1.medium.com/setup-nginx-ingress-controller-on-kubernetes-cluster-dd48b2b1ab61?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd48b2b1ab61</guid>
            <category><![CDATA[ingresscontroller]]></category>
            <category><![CDATA[nginx-ingress]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Sat, 07 Nov 2020 15:08:43 GMT</pubDate>
            <atom:updated>2020-11-07T15:08:43.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>When would you use this?</h3><p>Ingress is probably the most powerful way to expose your services, but can also be the most complicated. There are many types of Ingress controllers, from the <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer">Google Cloud Load Balancer</a>, <a href="https://github.com/kubernetes/ingress-nginx">Nginx</a>, <a href="https://github.com/heptio/contour">Contour</a>, <a href="https://istio.io/docs/tasks/traffic-management/ingress.html">Istio</a>, and more. There are also plugins for Ingress controllers, like the <a href="https://github.com/jetstack/cert-manager">cert-manager</a>, that can automatically provision SSL certificates for your services.</p><p>Ingress is the most useful if you want to expose multiple services under the same IP address, and these services all use the same L7 protocol (typically HTTP). You only pay for one load balancer if you are using the native GCP integration, and because Ingress is “smart” you can get a lot of features out of the box (like SSL, Auth, Routing, etc)</p><p>Ingress is split into two main parts — Ingress resources and ingress controller</p><p><strong>Ingress Resources:</strong></p><p>Ingress Resources defines how you want the requests to the services to be routed. It contains the main routing rules.</p><p><strong>Ingress controller:</strong></p><p>The Ingress Controller is responsible for routing requests to the appropriate services within the Kubernetes cluster. How an Ingress Controller executes this task, is not explicitly defined by Kubernetes. Thus an Ingress Controller can handle requests in a way that works best for the cluster.</p><p>The Ingress Controller is responsible to monitor the Kubernetes cluster for any new Ingress resources. Based on the Ingress resource, the Ingress Controller will set up the required infrastructure to route requests accordingly.</p><h3>Deploy the NGINX Ingress Controller for Kubernetes</h3><p>1. To download the NGINX Ingress Controller for Kubernetes, run the following command:</p><pre>git clone <a href="https://github.com/nginxinc/kubernetes-ingress.git">https://github.com/nginxinc/kubernetes-ingress.git</a></pre><p>2. To choose the directory for deploying the Ingress Controller, run the following command:</p><pre>cd kubernetes-ingress/deployments/</pre><p>3. To create a dedicated namespace, service account, and TLS certificates (with a key) for the default server, run the following commands:</p><pre>kubectl apply -f common/ns-and-sa.yaml<br>kubectl apply -f common/default-server-secret.yaml</pre><p>4. To create a ConfigMap for customizing your NGINX configuration, run the following command:</p><pre>kubectl apply -f common/nginx-config.yaml</pre><p>5. To configure role-based access control (RBAC), create a ClusterRole, and then bind the ClusterRole to the service account from step 3. For example:</p><pre>kubectl apply -f rbac/rbac.yaml</pre><p>6. To deploy the Ingress Controller, run the following commands.</p><pre>kubectl apply -f deployment/nginx-ingress.yaml<br>kubectl get pods --namespace=nginx-ingress</pre><p>You receive output similar to the following:</p><pre>NAME                            READY   STATUS    RESTARTS   AGE<br>nginx-ingress-fb4f4b44c-xmq6z   1/1     Running   0          3d7h</pre><h3>Access the Ingress Controller and run your application.</h3><p>1. To apply your configuration, run the following commands:</p><pre>kubectl apply -f service/loadbalancer-aws-elb.yaml</pre><pre>kubectl get svc --namespace=nginx-ingress</pre><p>You receive output similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k779tJXaI6E3L5omqKWeJg.png" /></figure><p>2. To configure NGINX to use the PROXY protocol so that you can pass proxy information to the Ingress Controller, add the following keys to the Nginx-config.yaml file from step 4. For example:</p><pre>kind: ConfigMap<br>apiVersion: v1<br>metadata:<br>  name: nginx-config<br>  namespace: nginx-ingress<br>data:<br>  proxy-protocol: &quot;True&quot;<br>  real-ip-header: &quot;proxy_protocol&quot;<br>  set-real-ip-from: &quot;0.0.0.0/0&quot;</pre><p>Note: The proxy information is passed to the Ingress Controller through the ConfigMap that you created earlier.</p><p>3. To update the ConfigMap, run the following command:</p><pre>kubectl apply -f common/nginx-config.yaml</pre><p>4. Set up your deployments or microservices (for example, Bollywood, Hollywood, and Tollywood). See the following examples.</p><p>Note: This step assumes that you’re running three microservices (for demo purposes). The microservices are exposed internally with Kubernetes as the default type.</p><h3>Example:</h3><p>Here we deploy our 3 sample microservice application using k8s deployment.</p><h3><strong>Bollywood microservice deployment and svc YAML</strong></h3><p>bollywoodmicroservice.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: bollywood<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: bollywood<br>  template:<br>    metadata:<br>      labels:<br>        app: bollywood<br>    spec:<br>      containers:<br>      - name: bollywood<br>        image: harshal1098/ingressimages:bollywood</pre><pre>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: bollywood-svc<br>spec:<br>  ports:<br>  - port: 80<br>    targetPort: 10010<br>    protocol: TCP<br>  selector:<br>    app: bollywood</pre><p>2. To apply your configurations, run the following commands:</p><pre>kubectl apply -f bollywoodmicroservice.yaml</pre><h3><strong>Hollywood microservice deployment and svc YAML</strong></h3><p>hollywoodmicroservice.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: hollywood<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: hollywood<br>  template:<br>    metadata:<br>      labels:<br>        app: hollywood<br>    spec:<br>      containers:<br>      - name: hollywood<br>        image: harshal1098/ingressimages:hollywood</pre><pre>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: hollywood-svc<br>spec:<br>  ports:<br>  - port: 80<br>    targetPort: 10011<br>    protocol: TCP<br>  selector:<br>    app: hollywood</pre><p>2. To apply your configurations, run the following commands:</p><pre>kubectl apply -f hollywoodmicroservice.yaml</pre><h3><strong>Tollywood microservice deployment and svc YAML</strong></h3><p>tollywoodmicroservice.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: tollywood<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: tollywood<br>  template:<br>    metadata:<br>      labels:<br>        app: tollywood<br>    spec:<br>      containers:<br>      - name: tollywood<br>        image: harshal1098/ingressimages:tollywood</pre><pre>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: tollywood-svc<br>spec:<br>  ports:<br>  - port: 80<br>    targetPort: 10012<br>    protocol: TCP<br>  selector:<br>    app: tollywood</pre><p>2. To apply your configurations, run the following commands:</p><pre>kubectl apply -f tollywoodmicroservice.yaml</pre><p>After all 3 microservice deployments we can check output using</p><pre>kubectl get all</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*mqEfkelHZPyniuxa5HIyZA.png" /></figure><h3><strong>Now let&#39;s go ahead and try to create the ingress that will expose this Service that we have created, to the outside world.</strong></h3><h3><strong>Host-based routing ingress:</strong></h3><p>we are using multiple domain names to route the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*C6WYm_eqxPxWWkHDinPN9A.png" /><figcaption>movieingress host-based routing</figcaption></figure><p>In this example, we route the request based upon the hostname.</p><p>e.x: if the user hits the hostname <strong>bollywood.movies.com</strong> then Nginx ingress controller route this request to Bollywood microservice and the user only see the bollywood movie names.</p><p><strong>Testing host-based routing</strong>:</p><ol><li>create a host-based routing ingress “host-based.yaml”</li></ol><pre>apiVersion: extensions/v1beta1<br>kind: Ingress<br>metadata:<br>  name: movie-ingress<br>  namespace: default<br>spec:<br>  rules:<br>    - host: bollywood.movies.com<br>      http:<br>        paths:<br>          - backend:<br>              serviceName: bollywood-svc<br>              servicePort: 80<br>    - host: hollywood.movies.com<br>      http:<br>        paths:<br>          - backend:<br>              serviceName: hollywood-svc<br>              servicePort: 80<br>    - host: tollywood.movies.com<br>      http:<br>        paths:<br>          - backend:<br>              serviceName: tollywood-svc<br>              servicePort: 80</pre><p>2. To apply your configurations, run the following commands:</p><pre>kubectl apply -f host-based.yaml</pre><h3><strong>Output:</strong></h3><p>To see the host-based routing work properly or not, curl the hostname(domain name).</p><p>Below the image you see, when we try to curl on the <strong>bollywood.movies.com </strong>it’s given us only Bollywood movie&#39;s names, and when we try to hit <strong>hollywood.movies.com </strong>it gives us only Hollywood movie names.</p><p>so here routing is happened based upon the hostname hit by the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*w2aENdVNkh1LGEJSWOxA5w.png" /></figure><h3><strong>Path-based routing:</strong></h3><p>Path-based routing differ from host-based routing in the sense, we don’t have multiple domain names, all the URI is distinguished and routed from the PATH prefix under a single domain, for example, the above movies application can be access through the single URI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*Gn82Wx8g5Pv5TroLkJVwcg.png" /></figure><ol><li>create a path-based routing ingress “path-based.yaml”</li></ol><pre>apiVersion: extensions/v1beta1<br>kind: Ingress<br>metadata:<br>  name: movies<br>  annotations:<br>    nginx.ingress.kubernetes.io/rewrite-target: /<br>spec:<br>  rules:<br>  - host: newmovies.com<br>    http:<br>      paths:<br>      - path: /bollywood<br>        backend:<br>          serviceName: bollywood-svc<br>          servicePort: 80<br>      - path: /hollywood<br>        backend:<br>          serviceName: hollywood-svc<br>          servicePort: 80<br>      - path: /tollywood<br>        backend:<br>          serviceName: tollywood-svc<br>          servicePort: 80</pre><p>2. To apply your configurations, run the following commands:</p><pre>kubectl apply -f path-based.yaml</pre><h3><strong>Output:</strong></h3><ol><li>when the user hits the <strong>newmovies.com/&lt;/path&gt;</strong> hostname then the ingress controller routes the request based on the path given by the user to the specific microservices.</li></ol><p>e.x: path’s <strong>/bollywood, /hollywood, /tollywood</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*ETbYfJbCUpbtEiHEX3p6Ww.png" /></figure><p>2.if the user hits only <strong>newmovies.com </strong>or path other than define in the ingress.yaml then it gives<strong> </strong>an error message 404 not found.</p><h3>Thank you, if you have any doubt reach out to me</h3><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd48b2b1ab61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configure RBAC in Kubernetes using AWS IAM.]]></title>
            <link>https://katharharshal1.medium.com/configure-rbac-in-kubernetes-using-aws-iam-39ae25af0d9a?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/39ae25af0d9a</guid>
            <category><![CDATA[rbac-access-control]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Fri, 03 Jul 2020 12:51:05 GMT</pubDate>
            <atom:updated>2020-07-03T12:51:05.533Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*ZN-T6LzoI5xScMIOa_Cb4Q.png" /></figure><h3>Overview</h3><h3>Kubernetes RBAC</h3><p>RBAC, Role-based access control, is an authorization mechanism for managing permissions around Kubernetes resources. RBAC allows the configuration of flexible authorization policies that can be updated without cluster restarts.</p><p>In the RBAC API, a role contains rules that represent a set of permissions. Permissions are purely additive (there are no “deny” rules). A role can be defined within a namespace with a <em>Role</em>, or cluster-wide with a <em>ClusterRole</em>.</p><p><strong>Kubernetes Account Types:</strong></p><ol><li><strong>User Account</strong>: when a human wants to access a cluster using API resources like kubectl, API calls, etc.)</li><li><strong>Service Account</strong>: when processes in containers inside pods access the cluster.</li></ol><p>Now we see how users get access into the Kubernetes Cluster, the user passes through 2 stages.</p><ol><li>Authentication(AWS IAM)</li><li>Authorization(<strong>RBAC</strong>)</li></ol><h3>Authentication</h3><ol><li>Kubernetes uses client certificates, bearer tokens, an authenticating proxy, or HTTP basic auth to authenticate API requests through authentication plugins for creating a new user and authenticating them.</li></ol><p>2. But in the Blog, we can authenticate the User using AWS IAM Service, we follow the below diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*ZN-T6LzoI5xScMIOa_Cb4Q.png" /></figure><p>With EKS you can take advantage of using powerful AWS IAM implementation. EKS authentication layers support both IAM Users and IAM Roles.</p><p>Amazon EKS uses Amazon EKS uses <a href="https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html">aws-iam-authenticator</a>for authentication to your Kubernetes cluster and Kubernetes RBAC for authorization.</p><p><a href="https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html">aws-iam-authenticator</a>It is a tool to use AWS IAM credentials to authenticate to a Kubernetes cluster.</p><h3>How to create an IAM User</h3><ol><li>Go to your <a href="https://console.aws.amazon.com/">AWS Console</a> where you will find the <a href="https://console.aws.amazon.com/iam/home">IAM service</a> listed under the “Security, Identity &amp; Compliance” group. Inside the IAM dashboard click on the Users tab and click the “Add User” button.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8cZDviIHC8zvne1_BwRTA.jpeg" /></figure><p>2. Create a new user and allow the user <strong>programmatic access</strong> by clicking on the “Programmatic access” checkbox.</p><p>3. After the user is created, you will have access to the user’s <strong>Access Key ID</strong> and <strong>Secret Access Key</strong>. You will be required to use these keys in the next step.</p><h3>Configure the AWS CLI</h3><ol><li>Install AWS CLI on the EC2</li></ol><p><a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html">Installing or updating to the latest version of the AWS CLI</a></p><p>2. Use the below comment to configure the User.</p><pre>aws configure</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*69l4eaD-O75ajcDLQmPv4g.png" /></figure><p>So Authentication is completed, we going towards Authorization.</p><h3>Authorization(RBAC)</h3><p>For authorization of the user, we used an RBAC.</p><p>RBAC API objects.</p><ul><li><strong>Role</strong>: A role contains rules that represent a set of permissions within a namespace.</li><li><strong>Rolebinding: </strong>A role binding grants the permissions defined in a role to a user or group of users. It holds a list of subjects (users, groups, or service accounts), and a reference to the role being granted, Permissions can be granted within a namespace with a <em>RoleBinding.</em></li><li><strong>Clusterrole: </strong>A role contains rules that represent a set of permissions across cluster or cluster-wide.</li><li><strong>ClusterRoleBinding: </strong>A Clusterrole binding grants the permissions defined in a role to a user or group of users. It holds a list of subjects (users, groups, or service accounts), and a reference to the role being granted, Permissions can be granted cluster-wide with a <em>ClusterRoleBinding.</em></li></ul><h3>Example</h3><h4>Manage access(RBAC) for <strong>specific namespace:</strong></h4><blockquote>It should be noted that Roles and RoleBindings are namespaced, which means that the permissions can only be given for the Kubernetes resources that are in the same namespace as the Role and the RoleBinding. Also, it is without saying that a RoleBinding can only reference a Role that exists in its namespace<strong>.</strong></blockquote><p>Let’s say we have a User <strong>developer-user</strong> who wants to be able to <em>list</em> the pods in a namespace <strong>dev, </strong>Then the steps we need to follow</p><h4>1.Create namespace</h4><pre>kubectl create namespace dev</pre><p><strong>2.Create an RBAC Role to namespace</strong></p><p>In the example below, you can see a Role which allows listing pods in the namespace “dev”</p><pre># role.yaml <br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: Role<br>metadata:<br>  name: developer-user-role<br>  namespace: dev<br>rules:<br>- apiGroups: [&quot;*&quot;]<br>  resources: [&quot;pods&quot;]<br>  verbs: [&quot;list&quot;]</pre><p><strong>API groups</strong> : /api/v1 or /apis/extensions/v1beta1.</p><p><strong>Resources</strong>: Resource is the K8s object that a subject wants to access. It could be pods, deployments, services, etc</p><p><strong>Verbs</strong>: Verbs are the actions that a subject can do on resources. It could be the list, delete, create, watch, etc</p><p>Create the role:</p><pre>kubectl create -f role.yaml</pre><p><strong>3.Create RoleBinding for Role</strong></p><p>To give a user the permissions described in the previous Role it is necessary to create a RoleBinding. In the example below, the RoleBinding “developer-user-role-binding” binds the Role “developer-user-role” to the user “developer-user”</p><pre># rolebinding.yaml<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  name: developer-user-role-binding<br>  namespace: dev<br>subjects:<br>- kind: User<br>  name: developer-user<br>  apiGroup: rbac.authorization.k8s.io<br>roleRef:<br>  kind: Role<br>  name: developer-user-role<br>  apiGroup: rbac.authorization.k8s.io</pre><p><strong>Subjects</strong>: The subject is the entity that needs access. It could be a user or group or a service account.</p><p><strong>RoleRef</strong>: We bind the user with a role.</p><p>Create the RoleBinding:</p><pre>kubectl create -f rolebinding.yaml</pre><p><strong>4. Adding the user to the aws-auth configmap</strong></p><p>If you want to grant additional AWS users or roles the ability to interact with your EKS cluster, you must add the users/roles to the aws-auth ConfigMap within Kubernetes in the kube-system namespace.</p><p>You can do this by either editing it using the kubectl edit command:</p><pre>$ kubectl edit configmap aws-auth -n kube-system</pre><p>Add the user under the mapUsers as an item in the aws-auth ConfigMap:</p><pre>data:<br>  mapUsers: |<br>    - userarn: arn:aws:iam::12345678:user/developer-user<br>      username: developer-user<br>      groups:<br>      - developer-user-role</pre><p>mapUsers:</p><p>userarn: Add aws iam user arn.</p><p>username: Add the name of the user.</p><p>groups: put the role name</p><p><strong>Output:</strong></p><p>We give developer-user only pods access in <strong>dev namespace,</strong> so developer user can only view the pods in dev namespace and not able to access any other things like deployment, secret,replicaset, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y3ZTxTBwFWqvNZaDmgfThA.png" /></figure><h3>Manage access centralized using ClusterRole</h3><p>ClusterRoles and ClusterRoleBindings which are useful in the following cases:</p><ul><li>Give permissions for non-namespaced resources like nodes</li><li>Give permissions for resources in all the namespaces of a cluster</li></ul><h3>Example</h3><p>Let’s say we have a User <strong>developer-user</strong> who wants to perform all the activities such as create, list, get, delete pods across the Cluster</p><p>So basically give developer-user admin access to pods resources across the cluster.</p><p>Then the steps we need to follow</p><ol><li><strong>Create a Clusterrole</strong></li></ol><pre># clusterrole.yaml<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRole<br>metadata:<br>  name: adminpods<br>rules:<br>- apiGroups: [&quot;*&quot;]<br>  resources: [&quot;pods&quot;]<br>  verbs: [&quot;*&quot;]</pre><p><strong>API groups</strong> : /api/v1 or /apis/extensions/v1beta1.</p><p><strong>Resources</strong>: Resource is the K8s object that a subject wants to access. It could be pods, deployments, services, etc</p><p><strong>Verbs</strong>: Verbs are the actions that a subject can do on resources. It could be the list, delete, create, watch, etc</p><p>Create the Clusterrole:</p><pre>kubectl create -f clusterrole.yaml</pre><p><strong>2. Create a Clusterbinding</strong>.</p><p>In case you want to grant permissions for your IAM role in all namespaces, you can simply use ClusterRoleBinding as follows:</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: pods_cluster_role_binding<br>subjects:<br>- kind: User<br>  name: developer-user<br>  apiGroup: rbac.authorization.k8s.io<br>roleRef:<br>  kind: ClusterRole<br>  name: adminpods<br>  apiGroup: rbac.authorization.k8s.io</pre><p>Create the Clusterrolebinding:</p><pre>kubectl create -f clusterrolebinding.yaml</pre><h4>3. Adding the user to the aws-auth configmap</h4><p>You can do this by either editing it using the kubectl edit command:</p><pre>$ kubectl edit configmap aws-auth -n kube-system</pre><p>Add the user under the mapUsers as an item in the aws-auth ConfigMap:</p><pre>data:<br>  mapUsers: |<br>    - userarn: arn:aws:iam::123456789012:user/developer-user<br>      username: developer-user<br>      groups:<br>      - adminpods</pre><p>Group: give the cluster role name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*unQvfCVXkQwGkGYfv6MJtg.jpeg" /></figure><p>Output:</p><p>In the below image u see <strong>developer-user</strong> able to access all pods in Cluster.</p><p>developer-user able to get pods in <strong>dev</strong>, <strong>qa, default </strong>namespaces also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*fFArF9wzOAiFILoYspVj4A.png" /></figure><h3>More things to do:</h3><p>You can also perform different actions on different resources using adding below rules under the role or cluster role YAML file.</p><pre>rules:<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;events&quot;]<br>  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;]<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;pods&quot;, &quot;pods/log&quot;, &quot;pods/exec&quot;]<br>  verbs: [&quot;list&quot;, &quot;get&quot;, &quot;create&quot;, &quot;update&quot;, &quot;delete&quot;]<br>- apiGroups: [&quot;extensions&quot;, &quot;apps&quot;]<br>  resources: [&quot;deployments&quot;]<br>  verbs: [&quot;list&quot;, &quot;get&quot;, &quot;create&quot;, &quot;update&quot;, &quot;delete&quot;]<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;configmaps&quot;]<br>  verbs: [&quot;list&quot;, &quot;get&quot;, &quot;create&quot;, &quot;update&quot;, &quot;delete&quot;]<br>- apiGroups: [&quot;&quot;]<br>  resources: [&quot;secrets&quot;]<br>  verbs: [&quot;list&quot;, &quot;get&quot;, &quot;create&quot;, &quot;update&quot;, &quot;delete&quot;]</pre><h3>Conclusion</h3><p>In this blog, we done Authentication of users using AWS IAM service, we bypass the traditional way of doing authentication in Kubernetes such as client certificates, bearer tokens, an authenticating proxy, or HTTP basic auth.</p><p>Thank you, if you have any doubt reach out to me</p><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39ae25af0d9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Job & Cronjob]]></title>
            <link>https://katharharshal1.medium.com/kubernetes-job-cronjob-c1ebfc46273d?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1ebfc46273d</guid>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 18:08:04 GMT</pubDate>
            <atom:updated>2020-06-15T05:15:00.575Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Types of Jobs.</strong></p><ol><li>Run to completion(Jobs).</li><li>Scheduled(Cronjobs)</li></ol><h3>Jobs :</h3><ol><li>The main function of a job is to create one or more pods and tracks about the success of pods.</li><li>They ensure that the specified number of pods is completed successfully. When a specified number of a successful run of pods is completed, then the job is considered complete.</li><li>This is primarily used for performing a batch processing so as soon as we submit this job manifest file to API server pod will kick in and execute a task and when the task is completed it shut down by itself.</li><li>Running pod temporarily till the task is completed.</li></ol><p>5. when the job is completed pods go to the shutdown state.</p><p>Now we see how to use jobs in Kubernetes.</p><ol><li>Create a job.yaml file.</li></ol><pre>apiVersion: batch/v1<br>kind: Job<br>metadata:<br>  name: helloworld<br>spec:<br>  template:<br>    spec:<br>      containers:<br>      - name: busybox<br>        image: busybox<br>        command: [&quot;echo&quot;, &quot;Hello harshal!!!&quot;]<br>      restartPolicy: Never</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*VrTXYYgFqaPUmVuXcyR3kg.png" /></figure><p>here we just create a busybox pod and echo “hello harshal”</p><p>2. Create a job.</p><pre>kubectl create -f &lt;job.yaml&gt;</pre><p>3. The job has been scheduled and you can see the job is here.</p><p>you see the job completions 1/1 means job is completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*S1xbP_me0qY-0EjTJseP7g.png" /></figure><p>4. We can also see the job logs.</p><pre>kubectl describe job &lt;jobname&gt;</pre><p>Output: it says when the job actually started and when it completed and how long it took.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*LbSvN4hZ3N2NGHi0XxuJLA.png" /></figure><p>5. When the job is completed not gonna delete itself so we need to clean up.</p><pre>kubectl delete job &lt;jobname&gt;</pre><p>Now we see different types of job parameters.</p><ol><li>Completions.</li><li>parallelism.</li><li>backofflimit.</li><li>activeDeadlineSecond</li></ol><p><strong>Completions</strong></p><ol><li>completions: Basically the repetition of a process, default it’s 1.</li></ol><p>e.x: if we set completion as value 2, the jobs runes 2times.</p><p>2. In this pod runes one after another, when 1st pod completed then 2nd pod is started. it’s also called sequential processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*o6Z1i-k3DVx9GOaHE4RUTg.png" /></figure><p>3. See 2 pods are running and completions are also set to 2/2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*T-YPsqalJmiSqT2vq1xBBw.png" /></figure><p><strong>parallelism</strong></p><ol><li>In completions, we see jobs runners sequential one after another.</li><li>Using the parallelism we can set the limit that how many jobs can run in parallel</li></ol><p>e.x: if u set completion: 2, and parallelism:2 both the pods are running at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*_Xtnk3o9JFZTWcbOVi4N8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*xQTd2sJuNfMgEMSPwRdgGw.png" /></figure><p><strong>backoffLimit</strong></p><ol><li>If the container is failing to load the image or completing the job, then still it creates more pods one after another until it succeeds.</li><li>In this situation, backoffLimit is used.</li><li>We set the backoffLimit for the job , that not create more pods once it’s failed.</li></ol><p>E.X: backoffLimit:2, once pods failed 2 times it won’t create more pods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*RgnEgEQEopob-yNO1FK2Bg.png" /><figcaption>backoff.yaml</figcaption></figure><p>4. After backoffLimit reaches, we got the below message when you describe job</p><pre>kubectl describe job &lt;jobname&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*sv7ozAv_aSnw05BjpJCs-Q.png" /></figure><p><strong>activeDeadlineSecond</strong></p><ol><li>In we can set a threshold to say, if I know job taking 10 sec to come up, so I set an activeDeadlineSecond as a 10second.</li><li>If I set activeDeadlineSecond: 10s, then if pods taking more time then the 10second then pods are automatically terminated.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*F-ASGREYWYaj6XfyxMoy4g.png" /><figcaption>activeDeadlineSecond.yaml</figcaption></figure><p>3. See in the image pods are terminating automatically after 10s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*UEVEamkV_MJ2AAFIFBCicw.png" /></figure><h3>Scheduled(Cronjobs)</h3><p>A CronJob the object allows you to schedule Job execution rather than starting them manually.</p><p>Now we see how to use a cronjob.</p><ol><li>Create a Cronjob.yaml file.</li></ol><pre>apiVersion: batch/v1beta1<br>kind: CronJob<br>metadata:<br>  name: helloworld-cron<br>spec:<br>  schedule: &quot;* * * * *&quot;<br>  jobTemplate:<br>    spec:<br>      template:<br>        spec:<br>          containers:<br>          - name: busybox<br>            image: busybox<br>            command: [&quot;echo&quot;, &quot;Hello harshal!!!&quot;]<br>          restartPolicy: Never</pre><p>In the schedule I set the value is “* * * * *” means every 1 min job is triggered and the new pod is created.</p><p>2. Create a cronjob</p><pre>kubectl create -f &lt;cronjob.yaml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*qkEA0wm3aHH1GBMwvXhcvw.png" /></figure><p>3. After every 1 min, a new pod is created as we set off the scheduler.</p><p>output: see when the 60sec age of the 1 pod is completed 2nd pod is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*zr1ldUkWKTwzIZxl11axEg.png" /></figure><p>CronJob Parameter.</p><ol><li>SuccessfulJobHistoryLimit</li><li>failedJobHistoryLimit</li><li>suspending cronjobs</li><li>concurrency policy</li></ol><p><strong>SuccessfulJobHistoryLimit &amp; failedJobHistoryLimit</strong></p><ol><li>By default, the job holds the last 3 successful jobs and last 1failed jobs.</li><li>We changed the YAML file and set the successful job limit and failed job limits by ourself.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*JH7hx1jq4PJfyfaOU_eKMw.png" /></figure><p><strong>suspending cronjobs</strong></p><ol><li>As we see cronjob is continuously making new pods, at the specific scheduled time.</li><li>by default suspend: false, and if we want not to create new pods so we basically set the suspend: true. then no new pod is created after applying these changes.</li></ol><p>Output: you see 2 pods are created and when we apply the suspend: true, you won’t see any new jobs is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*1gQZ-uTE72DeRFiATX3yDQ.png" /></figure><p><strong>concurrency policy</strong></p><p>Concurrency means if the jobs miss its schedule for some reason it’s gonna create a another job.</p><p>basically concurrency means more than 1 jobs running at the same time.</p><p>It has three possible values — Forbird, Allow, and Replace.</p><p><strong>Forbid</strong>: if you don’t want concurrent executions of your job.</p><p><strong>Allow</strong>: will let multiple job instances run concurrently.</p><p><strong>Replace</strong>: as the concurrency policy, the currently running job will be stopped and a new job will be spawned</p><p>Thank you, if you have any doubt reach out to me</p><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1ebfc46273d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Secrets]]></title>
            <link>https://katharharshal1.medium.com/kubernetes-secrets-4c7e0c577f09?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c7e0c577f09</guid>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 14:41:59 GMT</pubDate>
            <atom:updated>2020-06-14T16:05:59.066Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why should we use Secrets?</h3><p>Many a time you will find that developer have hardcode credentials within there container image.</p><p>There are multiple risks of hard-coding credentials.</p><ol><li>Anyone having access to the container repository can easily fetch the credentials</li><li>The developer needs to have the credentials of the production system.</li><li>The update of credentials will lead to a new docker image built again.</li></ol><p>So to overcome these Risks we used Secrets in Kubernetes.</p><h3>Overview of Secrets</h3><ol><li>A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Such information might otherwise be put in a Pod specification or in an image.</li></ol><p>2. It allows customers to store secrets centrally to reduce the risk of exposure.</p><p>3. Stored inside ETCD database on Kubernetes Master</p><p>4. You can update the secret dynamically and the pod will get the updated value.</p><p>5. Limit of secrets not more than 1MB</p><p>6. Consuming secrets inside pods: 1. Volumes 2.Environment variables</p><p>Now we see how to create a Secrets in Kubernetes, There are 2 ways of creating a secret in Kubernetes.</p><ol><li>kubectl command-line tool</li><li>YAML file(manually)</li></ol><p><strong>Create a secret using kubectl command-line tool.</strong></p><ol><li>use the following cmd to create a secret.</li></ol><pre>kubectl create secret generic &lt;secretname&gt; --from-literal=username=&lt;username&gt; --from-literal=password=&lt;password&gt;</pre><p>Output: you see the secret is created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYmUeStbP94XCYwity8b5A.png" /></figure><p>Creates a Kubernetes secret using the <strong>YAML</strong> file.</p><p><strong>Using the YAML file.</strong></p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br> name: secret-demo<br>type: Opaque<br>data:<br> username: &lt;base64 encded value&gt;<br> password: &lt;base64 encoded value&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*ZYOnbvxxmnHZ9XG9oJuv3A.png" /><figcaption>Secret.yaml</figcaption></figure><p>1.here we give kind=secret, the name of the secret is secret-demo.</p><p>2. in this example I’m adding 2 key-value pairs username and password, so it has to be base64 encoded.</p><p>3. so to create a base64 encoded format use following cmd.</p><pre>echo -n &#39;&lt;username&gt;&#39; | base64</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*luAYw4f8arlVZf9b6U7BVQ.png" /></figure><p>4. Now we copy-paste this base64 values in our secrets.yaml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*JyN2QpevzOo688ZTk6CWFg.png" /></figure><p>5. let&#39;s create a secret resource.</p><pre>kubectl create -f &lt;filename.yaml&gt;</pre><p>6. Check the secret is created or not using the following command.</p><pre>kubectl get secret</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*0-9qlDKMfxx0xMKBKCgZfw.png" /></figure><p><strong>Consuming Secrets inside pods.</strong></p><ol><li>Consuming Secret Values from environment variables.</li></ol><p>2. Consuming Secret values from volumes.</p><p><strong>Consuming Secret Values from environment variables</strong></p><p>When we use this option the secret will get mounted as an environment variable which you can then use within your container.</p><ol><li>Create an env variable using the YAML.</li></ol><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: busybox<br>spec:<br>  containers:<br>  - image: busybox<br>    name: busybox<br>    command: [&quot;/bin/sh&quot;]<br>    args: [&quot;-c&quot;, &quot;sleep 600&quot;]<br>    env:<br>    - name: myusername<br>      valueFrom:<br>        secretKeyRef:<br>          name: secret-demo<br>          key: username</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*BJ8w5dJ4kgDlz9vjT_QsIg.png" /></figure><p>YAML IMP fields.</p><ol><li>Here in the YAML I basically create a pod, the name of the pod is busybox, and what I’m going to run is just a command to sleep for 600s(10min).</li></ol><p>2. <strong>env</strong>: Specify the name of the environment variable.</p><p>In my case -name: myusername (i want to call my environment variable as a myusername)</p><p>3. <strong>secretKeyRef: </strong>you should specify here from which secret you’re going to grab the value.</p><p>4. <strong>key: </strong>Specify which key use should grab.</p><p>2. Create the pod.</p><pre>kubectl create -f &lt;filename.yaml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*KnhfRd1v_bH1X5HjnLfCxQ.png" /></figure><p>3. After the pod is created, go inside in the pod using the following command.</p><pre>kubectl exec -it &lt;podname&gt; -- sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*569SrKUhqrtUvFvnbB86Wg.png" /></figure><p>4. Now we are inside the container and if I do env command list all the environment variables in your container.</p><pre>env | grep &lt;envfilename&gt;</pre><p>Output: We see my secrets inside the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*KCZmqCrS_hpm1ofzFGDaXA.png" /></figure><h4>Consuming Secret values from volumes<strong>.</strong></h4><ol><li>Create a volume.yaml</li></ol><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: busybox<br>spec:<br>  volumes:<br>  - name: secret-volume<br>    secret:<br>      secretName: secret-demo<br>  containers:<br>  - image: busybox<br>    name: busybox<br>    command: [&quot;/bin/sh&quot;]<br>    args: [&quot;-c&quot;, &quot;sleep 600&quot;]<br>    volumeMounts:<br>    - name: secret-volume<br>      mountPath: /mydata</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*p9LTvKTksVCeJpT0pOjCwQ.png" /></figure><ol><li>Here we going to mount volume inside your container so you’re gonna define volume, volume section under pods specification you’re creating a volume.</li><li>mount path is /mydata , so once I run the container and if I go to mydata you will have the 1 file for a key-value pair you have got in your secret resource.</li></ol><p>2. Create the volume file.</p><pre>kubectl create -f &lt;volumefilename.yaml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*zVQ_3nIiJcezP0sr8LNZ7w.png" /></figure><p>3. Now we go inside our pod, using the following command.</p><pre>kubectl exec -it &lt;podname&gt; -- sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*wvqqqEgObhFCsxIZHNlaiA.png" /></figure><p>4. When you do <strong>ls </strong>you see your directories of your container in this, we got <strong>mydata</strong> directory which we set in the yaml file as our mount path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*WF5eaUn_LXxxLGex9gTk2w.png" /></figure><p>5. Go to that mydata directory, in this directory you see a separate file is created for your key value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*2aNdr4jv88jrJ-YII60KuA.png" /></figure><p>when you read these files you got your username and password inside the container(pod)in decrypted format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*dFqTnZfoCNmzth5R03bLug.png" /></figure><p><strong>Advantage of Secrets.</strong></p><p>You can update the secret dynamically and the pod will get the updated value.</p><p>E.X :</p><ol><li>let change the secret.yaml file with new key-value pair.</li></ol><p>here I added a new key-value pair <strong>name.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*fUyrM4Dl2XQpElcTfxxI0w.png" /></figure><p>2. We apply the update yaml using the following command.</p><pre>kubectl apply -f &lt;secretfilename.yaml&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*3WV-MD-3LoPY1NCNtkFkuw.png" /></figure><p>We updated the secret resource but I haven’t deleted the pod yet, the pod is still running.</p><p>3. After updating the secret when we go inside the running pod, see the value is updated or not inside the container.</p><pre>kubectl exec -it &lt;podname&gt; -- sh</pre><p>4. When we go to our mount path, we got the updated changes inside the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*oe7HpJyvsQh7zt3pKV4SVw.png" /></figure><p>Thank you, if you have any doubt reach out to me</p><p><strong>LinkedIn : </strong><a href="https://www.linkedin.com/public-profile/settings?trk=d_flagship3_profile_self_view_public_profile">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c7e0c577f09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Autoscaling — Horizontal Pod Autoscaling(HPA), Vertical Pod Autoscaling(VPA) Using AWS…]]></title>
            <link>https://katharharshal1.medium.com/kubernetes-autoscaling-horizontal-pod-autoscaling-hpa-vertical-pod-autoscaling-vpa-using-aws-d34b0284fe44?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/d34b0284fe44</guid>
            <category><![CDATA[vpa]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[hpa]]></category>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 08:58:31 GMT</pubDate>
            <atom:updated>2020-06-15T07:54:45.125Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes Autoscaling — Horizontal Pod Autoscaling(HPA), Vertical Pod Autoscaling(VPA) Using AWS EKS</h3><p>HPA VS VPA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ES1vU8l-IzCsPBDF-CrXaA.png" /></figure><p><strong>Horizontal scaling</strong> means raising the amount of your instance. For example, adding new nodes to a cluster/pool. Or adding new pods by raising the replica count (Horizontal Pod Autoscaler).</p><p><strong>Vertical scaling</strong> means raising the resources (like CPU or memory) of each node in the cluster (or in a pool). This is rarely possible without creating a completely new node pool. When it comes to pods though, vertical scaling would mean to dynamically adjust the resource requests and limits based on the current application needs (Vertical Pod Autoscaler).</p><h3>Horizontal Pod Autoscaling(HPA)</h3><p>1.HPA scales the number of pods in a replication controller, deployment, replica set, or stateful set based on CPU utilization. HPA can also be configured to make scaling decisions based on custom or external metrics.</p><p>2. This can help your applications scale out to meet increased demand or scale in when resources are not needed, thus freeing up your worker nodes for other applications.</p><p>3. you set a threshold to say for example if the CPU utilization goes 75% increase the number of replicas, that’s you horizontally scaling your application you’re adding more replicas to your existing application, and it autoscaled down when the CPU utilization drops below that threshold.</p><p>4. So in order to use horizontal pod autoscaling you have to have a matrics server in your cluster either hipster or metrics server.</p><ul><li>hipster is outdated so I’m gonna go with the metric server.</li></ul><h3>Install the metrics server</h3><p>1. The Kubernetes metrics server is an aggregator of resource usage data in your cluster.</p><p>2. The metrics server is not deployed by default in Amazon EKS clusters, but it provides metrics like CPU utilization, memory utilization, disk I/O that are required by the Horizontal Pod Autoscaler.</p><p><strong>To deploy the Metrics Server</strong></p><p>1.Deploy the Metrics Server with the following command:</p><pre>kubectl apply -f <a href="https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml">https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml</a></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tzyhtJonuTqIPqzPdNeHLA.png" /></figure><p>2. Verify that the metrics-server deployment is running the desired number of pods with the following command.</p><pre>kubectl get deployment metrics-server -n kube-system</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*KuzFF1zMFh-upJTf7FNZFg.png" /></figure><p><strong>To test your Horizontal Pod Autoscaler installation</strong></p><p>1. Create a simple Apache webserver application with the following command.</p><pre><strong>kubectl run httpd --image=httpd --requests=cpu=100m --limits=cpu=200m</strong></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*24JdbKp9PXGW10isVRemiA.png" /></figure><p>2. Create a Horizontal Pod Autoscaler resource for the httpd deployment.</p><p>2 way of doing this</p><ol><li>We can run it as a comment</li></ol><pre><strong>kubectl autoscale deployment httpd --cpu-percent=50 --min=1 --max=10 </strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*EAA3Hnk0lvChrt5qrVDatQ.png" /><figcaption>hpadeployment</figcaption></figure><p>2. Run it as a yaml file.</p><p>Create a hpa.yaml file.</p><pre>apiVersion: autoscaling/v1<br>kind: HorizontalPodAutoscaler<br>metadata:<br> name: httpd<br>spec:<br> maxReplicas: 10<br> minReplicas: 1<br> scaleTargetRef:<br> apiVersion: extensions/v1beta1<br> kind: Deployment<br> name: hppd<br> targetCPUUtilizationPercentage: 50</pre><ul><li>deploy it using below comment:</li></ul><p><strong>kubectl create -f &lt;filename.yaml&gt;</strong></p><ul><li>This command creates an autoscaler that targets 50 percent CPU utilization for the deployment, with a minimum of one pod and a maximum of ten pods.</li><li>When the average CPU load is below 50 percent, the autoscaler tries to reduce the number of pods in the deployment, to a minimum of one. When the load is greater than 50 percent, the autoscaler tries to increase the number of pods in the deployment, up to a maximum of ten.</li></ul><p>3. Describe the autoscaler with the following command to view its details.</p><pre><strong>kubectl describe hpa/httpd</strong></pre><p>As you see on the output the current CPU load is 1%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oACpuxyQsi-c51_9hqapEg.png" /></figure><p>4. Create a load for the webserver. The following command uses the Apache Bench program to send hundreds of thousands of requests to the httpd server. This should significantly increase the load and cause the autoscaler to scale out the deployment.</p><pre><strong>kubectl run apache-bench -i --tty --rm --image=httpd -- ab -n 500000 </strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BErTWMS1MutvfbXA_J1jYw.png" /><figcaption>loadapache</figcaption></figure><p>5. Watch the httpd deployment scale out while the load is generated. To watch the deployment and the autoscaler, periodically run the following command.</p><pre><strong>kubectl get horizontalpodautoscaler.autoscaling/httpd</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*-5CruY3cFwwUnqlNL4Pjzw.png" /></figure><p>6.when the load is increased and goes above 50%(targercpuutlization) horizontal pod autoscaler tries to increase the number of pods in the deployment, up to a maximum of ten.</p><p>In the output, we see the 10 https pod(replicas) is created by HPA, When the load finishes, the deployment should scale back down to 1.</p><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*ezqIzohzuJLI7iFTT2JH3A.png" /></figure><h3>Vertical Pod Autoscaling</h3><p><strong>1. Vertical scaling</strong> means raising the resources (like CPU or memory) of each node in the cluster (or in a pool).</p><p>2. This is rarely possible without creating a completely new node pool. When it comes to pods though, vertical scaling would mean to dynamically adjust the resource requests and limits based on the current application needs (Vertical Pod Autoscaler).</p><h3>VPA components</h3><h3>VPA Recommender</h3><p>The Recommender looks at the metric history, OOM events, and the VPA spec of deployment and suggests fitting values for requests (and limits). Hence the Recommender could just be used by itself if one is unsure what the application actually needs. Further down we see resource suggestions for our example app.</p><h3>VPA Auto Adjuster</h3><p>Whatever the Recommender will recommend, the Adjuster will implement if the updateMode: Auto is defined.</p><h3>Example</h3><h3>Install the metrics server</h3><p>1.Deploy the Metrics Server with the following command:</p><pre>kubectl apply -f <a href="https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml">https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml</a></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fowMuw_nfLPjCRdU5EKzNA.png" /></figure><p>2.Verify that the metrics-server deployment is running the desired number of pods with the following command.</p><pre>kubectl get deployment metrics-server -n kube-system</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*TAE1cbNwB0kLIPhUjjbpBw.png" /></figure><p>3. we can also see how metrics server provides metrics like CPU utilization, memory utilization, using the following comment.</p><pre>kubectl top nodes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*7qdAMgWFPx3QaLvVUAJRdg.png" /></figure><h3>Deploy the Vertical Pod Autoscaler</h3><ol><li>Clone the <a href="https://github.com/kubernetes/autoscaler">kubernetes/autoscaler</a> GitHub repository.</li></ol><pre><strong>git clone </strong><a href="https://github.com/kubernetes/autoscaler.git"><strong>https://github.com/kubernetes/autoscaler.git</strong></a><strong> </strong></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*EAC8IGZX2MOPEH-YLiGovw.png" /></figure><p>2. Change to the vertical-pod-autoscaler directory.</p><pre><strong>cd autoscaler/vertical-pod-autoscaler/</strong></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*MM3k1ya8t0FRR07-_Ss-3g.png" /></figure><p>3. Deploy the Vertical Pod Autoscaler to your cluster with the following command.</p><pre><strong>./hack/vpa-up.sh</strong></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*a9l7PnM7wV7VijJLrgYbjQ.png" /></figure><p>4. Verify that the Vertical Pod Autoscaler pods have been created successfully.</p><pre><strong>kubectl get pods -n kube-system</strong></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*R7_aOMdzazQkTmFWHqxI0Q.png" /></figure><p>Show you how it’s connected to your deployment.</p><ol><li>Deploy a php-apache application into the k8s.</li></ol><p>vim apache.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: php-apache<br>  labels:<br>    app: php-apache<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: php-apache<br>  template:<br>    metadata:<br>      labels:<br>        app: php-apache<br>    spec:<br>      containers:<br>      - name: php-apache<br>        image: k8s.gcr.io/hpa-example<br>        ports:<br>        - containerPort: 80<br>        resources:<br>          requests:<br>            cpu: 50m<br>            memory: 100Mi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*OkM6keEPTY0kLqPgpxsc8Q.png" /></figure><p>2. Deploy the application using the following comment</p><pre><strong>kubectl create -f &lt;filename.yaml&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*TtMBN5zuBfQsT8CSXJxU_w.png" /></figure><p>3. Check the CPU and memory utilization of the pods</p><pre><strong>kubectl describe deployment &lt;deployment-name&gt;</strong></pre><ul><li>You see in the requests</li></ul><p>CPU: 50m</p><p>memory: 100Mi</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*69uGOOVvDtvzJZCMIjQDjA.png" /></figure><p>4. Deploy the VPA.</p><p>vpa.yaml file.</p><pre>apiVersion: autoscaling.k8s.io/v1<br>kind: VerticalPodAutoscaler<br>metadata:<br> name: php-apache<br>spec:<br> targetRef:<br> apiVersion: &quot;apps/v1&quot;<br> kind: Deployment<br> name: php-apache<br> updatePolicy:<br> updateMode: &quot;Auto&quot;</pre><ul><li>Change the “php-apache” with your deployment name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*UUo5Jomb6CWg4amJpXixOA.png" /></figure><p>5. After deployment of VPA, describe the VPA.</p><pre><strong>kubectl describe vpa</strong></pre><ul><li>and you see <strong>Recommendation</strong>, VPA recommended you the <strong>Target</strong> CPU, memory value for your pod.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*CjwEJo3sXuuDiPsJvpuYwA.png" /></figure><p>6. In the vpa.yaml file, we set <strong>updateMode: “Auto”</strong></p><p>so VPA launches a new pod with <strong>Target</strong> CPU and Memory value, and terminated old one.</p><ul><li>In the Output, you see the new pod is created 34s ago, with new CPU and Memory value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*2RKs0N7LSj3Cjy6F7ncutg.png" /></figure><p>7. When we describe the newly created pod we see the CPU and Memory requested value is a change to <strong>Target </strong>value set by VPA.</p><ul><li>In the output, you see the</li></ul><p><strong>Requests(BeforeVPA):</strong></p><p>CPU: 50m</p><p>memory: 100Mi</p><p><strong>Requests(AfterVPA):</strong></p><p>CPU: 25m</p><p>memory: 262144k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*9d31pKcorTyBC9lbIKudhA.png" /></figure><p>Thank you, if you have any doubt reach out to me<br>LinkedIn : <a href="http://linkedin.com/in/harshal-kathar-b2a19b118">linkedin.com/in/harshal-kathar-b2a19b118</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d34b0284fe44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Cluster Autoscaling(CA)using AWS EKS.]]></title>
            <link>https://katharharshal1.medium.com/kubernetes-cluster-autoscaling-ca-using-aws-eks-4aab8c89f9a1?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aab8c89f9a1</guid>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Sun, 07 Jun 2020 15:07:31 GMT</pubDate>
            <atom:updated>2020-11-20T06:15:21.174Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes has 3 types of autoscaling groups.</p><ol><li>Cluster Autoscaling (CA).</li><li>Horizontal Pod Autoscaling(HPA).</li><li>Vertical Pod Autoscaling(VPA).</li></ol><p>Here HPA and VPA work at a pod level or application level, where CA is work at the Infrastructure level.</p><h3><strong>Cluster Autoscaling</strong></h3><ol><li>Cluster Autoscaling is a Kubernetes tool that increases or decreases the size of a Kubernetes cluster (by adding or removing nodes), based on the presence of pending pods and node utilization metrics.</li></ol><p>2. Cluster Autoscaler configured with the EC2 Autoscaling group.</p><p>3. The Cluster Autoscaler modifies your worker node groups so that they scale out when you need more resources and scale in when you have underutilized resources.</p><p>Follow the below steps to launch cluster autoscaling in your EKS.</p><h3><strong>Create an AWS EKS</strong></h3><p>*Go to my link where I explain in deep how to launch an AWS EKS.</p><p><a href="https://medium.com/@katharharshal1/deploying-a-kubernetes-cluster-with-amazon-eks-ae9f4ff18f77">Deploying a Kubernetes Cluster with Amazon EKS</a></p><h3><strong>Create an IAM Policy</strong> For Worker Node</h3><p>1. After the creation of EKS, The Cluster Autoscaler requires the following IAM permissions to make calls to AWS APIs on your behalf.</p><p>2. Go to IAM Console -&gt; Select Roles -&gt; Select the <strong>Worker node role</strong>.</p><p>3. Click on <strong>Add inline policy</strong>, and make a Custom policy with the following policy.</p><p>IAM Policy.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;autoscaling:DescribeAutoScalingGroups&quot;,<br>                &quot;autoscaling:DescribeAutoScalingInstances&quot;,<br>                &quot;autoscaling:DescribeLaunchConfigurations&quot;,<br>                &quot;autoscaling:DescribeTags&quot;,<br>                &quot;autoscaling:SetDesiredCapacity&quot;,<br>                &quot;autoscaling:TerminateInstanceInAutoScalingGroup&quot;,<br>                &quot;ec2:DescribeLaunchTemplateVersions&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;*&quot;<br>        }<br>    ]<br>}</pre><p>4. Paste this policy and create a custom policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x5ZzkYA801qvtc10N5MXzw.png" /><figcaption>EKSCustompolicy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUcjDiDO4ZEI5mn8pqQ1wA.png" /><figcaption>Workernoderole</figcaption></figure><h3><strong>Worker node ASG</strong></h3><p>1. Go to the EC2 Autoscaling group, you see there an autoscaling group of the EKS.</p><p>2. Check the min and max configuration of your worker nodes.</p><p>3.if your max capacity=2 and you already launch a 2 worker node, the Cluster Autoscaler not Spain the new node when the load is increased.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*uIuMPvSZ_s7qxYWhJrNYSw.png" /></figure><p>4. So change the Min and Max configuration.</p><p>E.X: Min=2 , Max= 5.</p><h3>Deploy the Cluster Autoscaler</h3><p>1. Deploy the Cluster Autoscaler to your cluster with the following command.</p><pre><strong>kubectl apply -f https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml</strong></pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RWOr_HlwJrnb2RFtVaO2g.png" /><figcaption>CAdeployment</figcaption></figure><p>2. Add the cluster-autoscaler.kubernetes.io/safe-to-evict annotation to the deployment with the following command.</p><pre>kubectl -n kube-system annotate deployment.apps/cluster-autoscaler cluster-autoscaler.kubernetes.io/safe-to-evict=&quot;false&quot;</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RESV3hINOqn4ZaQkBxJIVw.png" /></figure><p>3. Edit the Cluster Autoscaler deployment with the following command.</p><pre>kubectl -n kube-system edit deployment.apps/cluster-autoscaler</pre><p>Edit the cluster-autoscaler container command to replace <em>&lt;YOUR CLUSTER NAME&gt;</em> with your cluster&#39;s name, and add the following options.</p><ul><li><em>--balance-similar-node-groups</em></li><li><em>--skip-nodes-with-system-pods=false</em></li></ul><p>Save and close the file to apply the changes.</p><pre>spec:<br>      containers:<br>      - command:<br>        - ./cluster-autoscaler<br>        - --v=4<br>        - --stderrthreshold=info<br>        - --cloud-provider=aws<br>        - --skip-nodes-with-local-storage=false<br>        - --expander=least-waste<br>        - --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/&lt;YOUR CLUSTER NAME&gt;<br>        - --balance-similar-node-groups<br>        - --skip-nodes-with-system-pods=false</pre><p>*See the image you get an idea, how to edit the autoscaler deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Pig5ymQl69C8ecgb7xpL2A.png" /></figure><p>4. Set the Cluster Autoscaler image tag to the version that you recorded in the previous step with the following command. Replace <em>1.15.n</em> with your own value. You can replace us with <em>asia</em> or <em>eu</em>.</p><pre>kubectl -n kube-system set image deployment.apps/cluster-autoscaler cluster-autoscaler=us.gcr.io/k8s-artifacts-prod/autoscaling/cluster-autoscaler:v1.15.n</pre><p>output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4Byy_DYuI2eMqlYxbnYdA.png" /></figure><ul><li>find the latest Cluster Autoscaler version that matches your cluster’s Kubernetes major and minor version follow the below link.</li></ul><p><a href="https://github.com/kubernetes/autoscaler/releases">Releases · kubernetes/autoscaler</a></p><h3>View your Cluster Autoscaler logs</h3><p>View your Cluster Autoscaler logs with the following command.</p><pre>kubectl -n kube-system logs -f deployment.apps/cluster-autoscaler</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzzaN8KtbmTw7zdgeOF_2g.png" /><figcaption>LOGS.</figcaption></figure><p>You see calculating unneeded nodes , but if something is not right then you see doesn’t have the access that kind of message.</p><h3><strong>Checking Cluster Autoscaler Working</strong></h3><ol><li>Deploy a 1 sample application.</li></ol><p>vim deployment.yaml</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: php-apache<br>  labels:<br>    app: php-apache<br>spec:<br>  replicas: 20<br>  selector:<br>    matchLabels:<br>      app: php-apache<br>  template:<br>    metadata:<br>      labels:<br>        app: php-apache<br>    spec:<br>      containers:<br>      - name: php-apache<br>        image: k8s.gcr.io/hpa-example<br>        ports:<br>        - containerPort: 80<br>        resources:<br>          requests:<br>            cpu: 500m<br>            memory: 256Mi<br>          limits:<br>            cpu: 1000m<br>            memory: 512Mi</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*YgKfTUxhjzEf0USjl7qJ_w.png" /></figure><p>2. Deployed the application using the following command.</p><pre>kubectl create -f &lt;filename.yaml&gt;</pre><p>3. Here Cluster Autoscaler just looks at the requester and sees if the requester CPU goes above the available node CPU and if it’s just scaling the node.</p><ul><li>In this example, we need a 10v CPU.</li></ul><p>4. So after the deployment <strong>cluster autoscaler check the node every 10s, </strong>an if it finds that node is insufficient to handle the request and start making new nodes using EC2 autoscaling Group.</p><ul><li>for your reference I attached the images, here you see when I create a deployment which as requested more CPU, the EC2 autoscaling group starts making new nodes to handle this request.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C7K2kYIp5WrFIWdKhzLjZg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*idOSqwLKNrT9KHqqCn3_fg.png" /></figure><ul><li>To see the new nodes created or not on the cluster side, run the following comment.</li></ul><pre>kubectl get nodes</pre><p>here you see in image new 3 nodes are created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*Z8n9h5-xlV3jmfLtLFK0Hg.png" /></figure><p>Thank you, if you have any doubt reach out to me<br>LinkedIn : <a href="http://linkedin.com/in/harshal-kathar-b2a19b118">linkedin.com/in/harshal-kathar-b2a19b118</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RlWub4GT0W45H4lxEZ3s7g.png" /><figcaption>kubernets.io</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aab8c89f9a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Objects — Pods, ReplicaSets, and Deployments]]></title>
            <link>https://katharharshal1.medium.com/kubernetes-objects-pods-replicasets-and-deployments-44f16b38d9f7?source=rss-88fc6c498f63------2</link>
            <guid isPermaLink="false">https://medium.com/p/44f16b38d9f7</guid>
            <dc:creator><![CDATA[Harshal Kathar]]></dc:creator>
            <pubDate>Sun, 31 May 2020 18:27:34 GMT</pubDate>
            <atom:updated>2020-06-15T06:26:08.313Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes Objects — Pods, ReplicaSets, and Deployments</h3><h3>Pods</h3><ol><li>Kubernete&#39;s ultimate goal is to deploy the application using containers on a set of machines they are configured as a Worker node.</li><li>Kubernetes does not deploy containers directly to the worker node.</li><li>The container is encapsulated in the Kubernetes object known as POD.</li><li>Docker is the most common container runtime used in a Kubernetes Pod, but Pods support other container runtimes as well</li><li>Each Pod is meant to run a single instance of a given application.</li><li>If you want to scale your application horizontally, you should use multiple Pods, one for each instance.</li><li>Each pod has it’s own Ip address.</li></ol><h3>How to create a pod</h3><ol><li>Create a YAML file for pod</li><li>vim &lt;filename.yaml&gt;</li></ol><p>sample nginx.yaml file</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: nginx<br>  labels:<br>    name: nginx<br>spec:<br>  containers:<br>  - image: nginx<br>    name: nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*Rqtal6obxzvUpTBOFJiTAw.png" /></figure><p>3. create a pod using below comment</p><pre><strong>kubectl create -f &lt;filename.yaml&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*Hmnn67r6ETy6AizxUyXrBw.png" /></figure><p>4. To check pod is created or not.</p><pre><strong>kubectl get pod</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*4aeWg97mds3qzYQZ3bbQiw.png" /></figure><p>5. To delete the exiting pod</p><pre><strong>kubectl delete pod &lt;podname&gt;</strong></pre><h3>ReplicaSets</h3><ol><li>A ReplicaSet’s purpose is to maintain a stable set of replica Pods running at any given time.</li></ol><p>2. In the replica sets, we used the selector.</p><p>3. The <strong>selector</strong> is used to identifying the Pods it can acquire.</p><p>4. a number of replicas indicating how many Pods it should be maintaining.</p><p>5. <strong>pod template</strong> specifying the data of new Pods it should create to meet the number of replicas criteria, When a ReplicaSet needs to create new Pods, it uses its Pod template.</p><p>6. using replica set you can easily run multiple pods of given instances.</p><h3>How to create a replica set</h3><ol><li>Create a replica set yaml file.</li><li>vim &lt;filename.yaml&gt;</li></ol><p>E.X : nginxreplicaset.yaml</p><pre>apiVersion: apps/v1<br>kind: ReplicaSet<br>metadata:<br> name: frontend<br> labels:<br> app: nginx<br> tier: frontend<br>spec:<br> # modify replicas according to your case<br> replicas: 3<br> selector:<br> matchLabels:<br> tier: frontend<br> template:<br> metadata:<br> labels:<br> tier: frontend<br> spec:<br> containers:<br> - name: nginxreplicaset<br>   image: nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*vh_4qTYgEZoDwOVPT8XZWw.png" /></figure><p>*here we set replicas = 3, so 3 pods must running at every time</p><p>2. create a replica set</p><pre><strong>kubectl create -f &lt;filename.yaml&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*YL6I0iXAL9t-1RLn-cVdVg.png" /></figure><p>3. You can then get the current ReplicaSets deployed:</p><pre><strong>kubectl get rs</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*eUhg9G6nGSpoqjQ5VcxM1w.png" /></figure><p>4. To scale up the replica set.</p><pre><strong>kubectl scale --replicas=5 -f &lt;filename.yaml&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*e_hN21ekW4v089h7OZDi6w.png" /></figure><p>5. To see you pods</p><pre><strong>kubectl get pod</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*Mv7tIUswf7WUhaJyUhr3qA.png" /></figure><h3>Deployments</h3><ol><li>A <em>Deployment</em> provides declarative updates for Pods and Replicaset.</li><li>Deployments wrap up Pods and ReplicaSets into a nice package that is capable of deploying your applications.</li><li>A deployment is an object in Kubernetes that lets you manage a set of identical pods.</li><li>Without a deployment, you’d need to create, update, and delete a bunch of pods manually.</li><li>With a deployment, you declare a single object in a YAML file. This object is responsible for creating the pods, making sure they stay up to date and ensuring there are enough of them running</li><li>You can also easily autoscale your applications using a Kubernetes deployment.</li><li>we also update the image in the pod and after updating the pod if the image is failing then we able to roll out it to the old image, as called as ”Rolling Back a Deployment ”</li><li>using deployment we can undo deployment, pause deployment, resume deployment.</li></ol><h3>How to create a Deployment.</h3><ol><li>create a deployment.yaml file</li></ol><p>We will create a Deployment configuration file that defines the same state as our ReplicaSet example. Actually, you will notice that the only change between declaring a Deployment and a ReplicaSet is the kind</p><p>* sample Nginx deployment YAML</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx<br>        ports:<br>        - containerPort: 80</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*KKRySPFxRb6TY05WTVc4jw.png" /></figure><ul><li>First, the replicas key sets the number of instances of the pod that the deployment should keep-alive</li><li>Next, we use a label selector to tell the deployment in which pods are part of the deployment. This essentially says “all the pods matching these labels are grouped in our deployment.”</li><li>pod template jammed inside our deployment spec. When the deployment creates pods, it will create them using this template.</li></ul><p>2. Create the Deployment by running the following command:</p><pre><strong>kubectl create -f &lt;filename.yaml&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*1dXXTnSv2c0miZjXzWN0rg.png" /></figure><p>3. Run kubectl get deployment to check if the Deployment was created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*0yvaVzJy6jHBOwtDvOQ46A.png" /></figure><p>4. To see the Deployment rollout status, run</p><pre>kubectl rollout status deployment &lt;deploymentname&gt;</pre><p>5. Updating the deployment</p><p>e.x: Let’s update the Nginx Pods to use the nginx:1.16.1 image instead of the nginx:1.14.2 image.</p><pre>kubectl set image deployment/nginx-deployment nginx=nginx:1.16.1 --record</pre><p>The output is similar to this:</p><pre>deployment.apps/nginx-deployment image updated</pre><p>6. Rolling Back a Deployment</p><p>1.when the Deployment is not stable, such as crash looping, you may want to rollback a Deployment.</p><p>2. Suppose that you made a typo while updating the Deployment, by putting the image name as nginx:1.161 instead of nginx:1.16.1 and your deployment getting crash or failed.</p><pre>kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.161 --record=true</pre><p>The output is similar to this:</p><pre>deployment.apps/nginx-deployment image updated</pre><p>*and after this, your deployment is failed because you select wrong image version.</p><ul><li>To fix this, you need to roll back to a previous revision of Deployment that is stable.</li></ul><p>rolling back to the previous version.</p><p><strong>kubectl rollout undo deployment.v1.apps/nginx-deployment</strong></p><p>Alternatively, you can rollback to a specific revision by specifying it with --to-revision:</p><pre>kubectl rollout undo deployment.v1.apps/nginx-deployment --to-revision=2</pre><p>7. Checking Rollout History of a Deployment</p><pre>kubectl rollout history deployment.v1.apps/nginx-deployment</pre><p>8. Scaling a deployment.</p><pre>kubectl scale deployment.v1.apps/nginx-deployment --replicas=10</pre><p>9. Pausing and Resuming a Deployment</p><pre>kubectl rollout pause deployment.v1.apps/nginx-deployment</pre><p>**After a pause the deployment, you can make many updates as u wish no new rollout started:</p><p>Resume the Deployment</p><pre>kubectl rollout resume deployment.v1.apps/nginx-deployment</pre><p>Thank you, if you have any doubt reach out to me<br>LinkedIn : <a href="http://linkedin.com/in/harshal-kathar-b2a19b118">linkedin.com/in/harshal-kathar-b2a19b118</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7RQ7q6bp_qH3XInq79M0w.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44f16b38d9f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>