Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
17 views
k8s Basic
Uploaded by
Damian
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save k8s_basic For Later
Download
Save
Save k8s_basic For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
17 views
k8s Basic
Uploaded by
Damian
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save k8s_basic For Later
Carousel Previous
Carousel Next
Save
Save k8s_basic For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 21
Search
Fullscreen
Learn Kubernetes Basics #1: Ceeate a Clustes 01.1: Using Minikube to Create a Cluster + 2:Deployan Aen 92.1; Using kubect! to Create a Deployment + 3: Explore Your App © 3.1: Viewing Pods and Nodes + 4: Expose Your App Publicly © 4.1: Using a Service to Expose Vour App. + 5: Seale Your App © 5.1: Running Multiple instances of Your App + 6: Update Vour ay 9 6.1: Performing a Rolling Uedate, Kubernetes Basics ‘This tutorial provides a walkthrough of the basics of the Kubernetes cluster orchestration system, Each module contains some background information on major Kubernetes features and concepts, and includes an interactive online tutorial. These interactive tutorials let you manage a simple cluster and its containerized applications for yourself. Using the interactive tutorials, you can learn to: * Deploy a containerized application on a cluster. *# Scale the deployment. ‘Update the containerized application with a new software *# Debug the containerized application What can Kubernetes do for you? With modern web services, users expect applications to be available 24/7, and developers expect to deploy new versions of those applications several times a day. Containerization helps package software to serve these goals, enabling applications to be released and updated without downtime, Kubernetes helps you make sure those containerized applications run where and when you want, and helps them find the resources and tools they need to work. Kubernetes is a production-ready, open source platform designed with Google's accumulated experience in container orchestration, combined with best-of-breed ideas from the community. Kubernetes Basics Modules1.Create a Kubernetes cluster 4. Expose your app publicly 2.Deploy an app. 3. Explore your app ®1 - Create a Cluster Learn about Kubernetes cluster and create a simple cluster using Minikube. 1.1 - Using Minikube to Create a Cluster Learn what a Kubernetes cluster is, Learn what Minikube is, Start a Kubernetes cluster Objectives + Learn what a Kubernetes cluster is, * Learn what Minikube is «Start a Kubernetes cluster on your computer. Kubernetes Clusters Kubernetes coordinates a highly available cluster of summary: computers that are connected to work as a single unit. + Kubernetes ‘The abstractions in Kubernetes allow you to deploy cluster containerized applications toa cluster without tying them + Minikube specifically to individual machines. To make use of this new model of deployment, applications need to be packaged in a way that decouples them from individual hosts: they need to be containerized. Containerized applications are more flexible and available than in past deployment models, where applications were installed directly onto specific machines as packages deeply integrated into the host, Kubernetes automates the distribution and scheduling of application containers across a cluster in a more efficient way. Kubernetes is ‘an open-source platform and is production-ready. A Kubernetes cluster consists of two types of resources: ‘= The Control Plane coordinates the cluster + Nodes are the workers that run applications Cluster Diagram‘The Control Plane is responsible for managing the luster. The Control Plane coordinates all activites in your cluster, such as scheduling applications, maintaining, applications’ desired state, scaling applications, and rolling out new updates, Anode is a VM or a physical computer that serves as a worker machine in a Kubernetes cluster. Each node has ‘a Kubelet, which is an agent for managing the node and communicating with the Kubernetes control plane. The node should also have tools for handling container operations, such as containerd or CRO. A Kubernetes cluster that handles production trafic should have 3 minimum of three nodes because if one nade goes down, both an etcd member and a control plane instance are lost, and redundancy is compromised. You can mitigate this risk by adding more control plane nodes. When you deploy applications on Kubernetes, you tell the control plane to start the application containers. The control plane schedules the containers to run on the cluster's nodes. Nodelevel components, such as the kubelet, communicate with the control plane using the Kubernetes API, which the control plane exposes. End users can also use the Kubernetes API directly to interact with the cluster ‘A Kubernetes cluster can be deployed on either physical or virtual machines. To get started with Kubernetes development, you can use Minikube, Minikube is a lightweight Kubernetes implementation that creates a VM (on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, ‘macOS, and Windows systems, The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete. Now that you know more about what Kubernetes is, visit Hello Minikube to try this out on your computer. ‘Once you've done that, move on to Using kubect] to create a Deployment2 - Deploy an App 2.1 - Using kubectl to Create a Deployment Learn about application Deployments. Deploy your first app on Kubernetes with kubect. Objectives + Learn about application Deployments. + Deploy your first app on Kubernetes with kubect. Kubernetes Deployments Once you have a running Kubernetes cluster, you ¢an Summary: deploy your containerized applications on top of t. To do + Deployments 50, you create a Kubernetes Deployment. The + Kubect Deployment instructs Kubernetes how to create and update instances of your application. Once you've created ‘a Deployment, the Kubernetes control plane schedules the application instances included in that Deployment to run on ingividual Nodes in the cluster. Once the application instances are created, a Kubernetes Deployment controller continuously monitors those instances. f the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster. This provides a self-healing mechanism to address ma‘ failure or maintenance. Ina pre-orchestration world, installation scripts would often be used to start applications, but they did not allow recovery from machine failure. By both creating your application instances and keeping them running across Nodes, Kubernetes Deployments provide a fundamentally different approach to application management. Deploying your first app on Kubernetes OrYou can create and manage a Deployment by using the Kubernetes command line interface, kubectl, Kubectl Uses the Kubernetes API to interact with the cluster. In this ‘module, youll learn the most common kubect! commands needed to create Deployments that run your applications. on a Kubernetes cluster. When you create Deployment, you'll need to specify the container image for your application and the number of replicas that you want to run. You can change that information later by updating your Deployment; Modules ‘Sand § of the bootcamp discuss how you can scale ang Update your Deployments, For your first Deployment, youll use a hello-node application packaged in a Docker container that uses NGINX to echo back all the requests (If you didn't already ty creating a hello-node application and deploying it using ‘a container, you can do that first by following the instructions from the Hello Minikube tutorial You will need to have installed kubectl as well. Ifyou need to insta it, visit install tools, Now that you know what Deployments are, le's deploy our first app! kubect! basics ‘The common format of a kubect! command is: kubect1 ‘This performs the specified action (Ike create, describe or delete) o deployment). You can use --help after the subcommand to get additional info about possible parameters (for example: kubectl get nodes --help). specified resource (like node or Check that kubect! is configured to talk to your cluster, by running the kubecth version command Check that kubect! i installed and you can see both the client ang the server versions. To view the nodes in the cluster, run the kubectl get nodes command, You see the available nodes. Later, Kubernetes will choose where to deploy our application based on Node available Deploy an app Lets deploy our frst app on Kuberneteswitn the latect crestedeplorent comand We need to provide the deployment name and app image locaton include the ful repository url for images hosted ouside Docker Hub). kubectl create deployment kubernetes-booteanp --inagengcr.so/google-sanples/kubernetes- boot anp:vt Great! You just deployed your first application by creating a deployment. This performed afew things for you: + searched for a suitable node where an instance of the application could be run (we have only 1 available node) ‘scheduled the application to run on that Node+ configured the cluster to reschedule the instance on a new Node when needed Tolist your deployments use the kubect get deploynents command: unectl get deployments We see that there is 1 deployment running a single instance of your app. The instance is running inside # container on your node. View the app Pods that are running inside Kubernetes are running on a private, isolated network. By default they are visible from other pods and services within the same Kubernetes cluster, but not outside that network. When we use kubectt , we're interacting through an API endpoint to communicate with our application We will cover other options on how to expose your application outside the Kubernetes cluster later, in Module 4 ‘The tubecti proxy command can create a proxy that will forward communications into the dluster-wide, private network. The proxy can be terminated by pressing control and wor't show any output while its running, You need to open a second terminal window to run the proxy. subectl proxy We now have a connection between our host (the terminal) and the Kubernetes cluster. he proxy enables direct access to the API from these terminals ‘You can see all those APIs hosted through the proxy endpoint, For example, we can query the version directly through the API using the curt command: curl hetp:/flocalhost :8901/version Note: If port 8001 is not accessible, ensure that the juboct’ proxy that you started above is running in the second terminal ‘The API server will automaticaly create an endpoint for each pod, based on the pod name, that is also accessible through the proxy. First we need to get the Pod name, and well store in the environment varlable POo_NAME: export Pon_Minces(kubectl get pods -o go-tenplate --tenplate “{{range -itens}) {{umetadata namey}{ Ca") €en8))") ‘cho Mane of the Pod: $700 MAME You can access the Pod through the proxied API, by running: curl ne {localhost :8001/2pi/v1/ranespaces/default/pods/$?00_NAME/ In order for the new Deployment to be accessible without using the proxy, a Service is. required which will be explained in Module 4 ‘Once you're ready, move on to Viewing Pods and Nodes.3 - Explore Your App 3.1 - Viewing Pods and Nodes Learn how to troubleshoot Kubernetes applications using kubect! get, kubect! describe, kubect! logs and kubect! exec. Objectives + Learn about Kubernetes Pods. + Learn about Kubernetes Nodes. + Troubleshoot deployed applications. Kubernetes Pods summary: When you created a Deployment in Module 2 Kubernetes "pode created a Pod ta host your application Instance. APod isa ree. Kuveretes abstraction that represents a group of one or LESS na more application containers (such 5 Docker and some Kebeat ma shared resources for those containers. Those resources include: Shared storage, as Volumes Networking, as 8 unique cluster IP address + Information about how to run each container, such as the container image version or specific ports to ‘APod madels an application-specifc "logical host" and can contain different application containers which are relatively tightly coupled. For example, a Pod might include both the container with your Nodes app as well asa different container that feeds the data to be published by the Nodejs webserver. The cantainers in a Pod share an IP Address and port space, are always ¢o- located and co-scheduled, and run in a shared context on the same Node, Pods are the atomic unit on the Kubernetes platform, When we create a Deployment on Kubernetes, that Deployment creates Pods with containers inside them (as ‘opposed to creating containers directly). Each Pod is tied to the Node where itis scheduled, and remains there until termination (according to restart policy) or deletion. In case of a Node failure, identical Pods are scheduled on, other available Nodes in the cluster. Pods overview © (a) ax (eoNodes ‘APod always runs on a Node, A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster. Each Node is managed by the control plane. A Node can have multiple pods, and the Kubernetes control plane automatically handles scheduling the pods across the Nodes in the cluster. The control plane's automatic scheduling takes into account the avallable resources an each Node. Every Kubernetes Node runs at least + Kubelet, a process responsible for communication between the Kubernetes control plane and the Node; itrmanages the Pods and the containers running on a machine. *# Acontainer runtime (like Docker) responsible for palling the container image from a registry, unpacking the container, and running the application Node overview Troubleshooting with kubectl In Module 2, you used the kubectl command-line interface. Youll continue to use it in Module 3 tog information about deployed applications and their environments, The most common operations can be done with the following kubectl subcommands: # kubect get - list resources + kubect describe - show detailed information about a resource ‘= kubect Logs - print the logs from a container in a pod + kubect1 exec - execute a command on a container inapod You can use these commands to see when applications were deployed, what their current statuses are, where they are running and what thelr configurations are. Now that we know more about our cluster components ‘and the command line, let's explore our application.Check application configuration Let's verify hat the application we deployed in the previous scenario is running, We'll use the kubectt get command and look for existing Pods: If no pods are running, please wait a couple of seconds and list the Pods again. You can continue once you see one Pod running. Next, to view what containers are inside that Pod and what images are used to build those containers we run the kubectl describe pods command ubectl describe pods We see here details about the Pod's container: IP address, the ports used and a lst of events related to the lifecycle of the Pod. ‘The output of the describe subcommand is extensive and covers some concepts that we didn't explain yet, but don't worry, they will become familiar by the end of this bootcamp. ‘Note: the describe subcommand can be used to get detailed information about most of the ‘ubernetes primitives, including Nodes, Pods, and Deployments. The describe output is designed to be human readable, not to be scripted ogainst. Show the app in the terminal Recall that Pods are running in an isolated, private network - so we need to proxy access to them so we can debug and interact with them, To do this, we'lluse the kubect? proxy command to run a proxy in a second terminal. Open 2 new terminal window, and in that new terminal, run’ eubect proxy Now again, we'll get the Pod name and query that pod directly through the proxy. To get the Pod name and store it in the POD_NAME environment variable: export POD_HAME="$(kubectl get pods -0 go-tenplate --tenplate "{(range -itens)} ‘{{umetadata name} VW" Cen8) "9° echo Nane of the Pod: $700_NAME To see the output of our application, run a curl request cu ne /ocalhost 8003 /2pi/v1/nanespaces/default/pods/$P00_ NAM ‘The URL isthe raute to the API of the Pod View the container logs Anything that the application would normally send to standard output becomes logs for the container within the Pad, We can retrieve these logs using the kubect1 logs command: kevbectl Logs "$°00_ NAME” ‘Note: We don't need fo specify the container name, becouse we only have one container inside the pod, Executing command on the container We can execute commands directly on the container once the Pod is up and running. For this, we use the exec subcommand and use the name of the Pod as a parameter. Let's list the environment variables: eubect exee “$P00_NAHE™ —- env Again, i's worth mentioning that the name of the container itself can be omitted since we only have a single container in the Pod. Next let's start a bash session in the Pod's container: keubectl exec -ti $700_NANE ~~ bashWe have now an open console an the container where we run our NodelS application. he source code of the app is in the server. 3s file: cat serverts You can check that the application is up by running a curl command: curl hetps//locatnost 8080 Note: here we used Locathost because we executed the command inside the NodefS Pod. If ‘you cannot connect to Jocalhost:8080, check to make sure you hove run the ubectt exec command and are launching the command from within the Pod To close your container connection, type exit4 - Expose Your App Publicly 4.1 - Using a Service to Expose Your App Learn about a Service in Kubernetes, Understand how labels and selectors relate to a Service. Expose an application outside a Kubernetes cluster. Objectives + Learn about a Service in Kubernetes «Understand how labels and selectors relate toa service + Expose an application outside a Kubernetes cluster usinga Service Overview of Kubernetes Services Kuberetes Pods are mortal Pods havea ifeqcle, When SUMMary worker node dies, the Pods running on the Node are also + Exposing Pods lost. A RealicaSat might then dynamically drive the cluster toexternal back tothe desired state via the creation of new Pods to traffic keep your application running. As another example, + Load balancing consider an image-processing backend with 3 replicas, traffic across ‘Those replicas are exchangeable: the front-end system ‘multiple Pods should not care about backend replicas or even ifa Pod is + Using labels lost and recreated, That said, each Pod in a Kubernetes cluster has a unique IP address, even Pods on the samme Node, so there needs to be a way of automaticaly reconciling changes among Pods so that your applications continue to function. AService in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them, Services enable a loose coupling between dependent Pods. A Service s defined using YAML oF JSON, like all Kubernetes object manifests, The set of Pods targeted by ‘a Service is usually determined by a label selector (see below for why you might want a Service without including 4a selector in the sped [Although each Pod has a unique IP address, those IPs are not exposed outside the cluster without a Service. Services allow your applications to receive traffic. Services can be exposed in different ways by specifying a type in the spec of the Service: ‘Cluster (default) - Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster. + NodePort- Exposes the Service an the same port of each selected Node in the cluster using NAT. Makes & Service accessible from outside the cluster using “hocerP>:
. Superset of Cluster!P. + LoadBolancer - Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Service. Superset of NodePort+ ExternalName - Maps the Service to the contents of the extemnainane fleld (e.g, foo.bar.exanple.con ) by returning a cxsne record with its value, No proxying, of any kind s set up. This type requires v1.7 or higher Of kabe-dns , or CoreDNS version 0.0.8 or higher. More information about the different types of Services can be found in the Using Source I tutorial. Also see ‘Connecting Applications with Services, ‘Additionally, note that there are some use cases with Services that involve not defining a selector in the spec. A Service created without setector will also not create the corresponding Endpoints object. This allows users to manually map a Service to specific endpoints. Another possibilty why there may be no selector is you are strictly Using type: externaiNane Services and Labels AService routes traffic across a set of Pods. Services are the abstraction that allows pods to die and replicate in Kubernetes without impacting your application. Discovery and routing among dependent Pods (such as the frontend land backend components in an application) are handled by Kubernetes Services, Services match a set of Pods using labels and selectors, a {grouping primitive that allows logical operation on objects in Kubernetes. Labels are key/value pairs attached to objects and can be used in any number of ways: * Designate objects for development, test, and production + Embed version tags + Classify an object using tags 9 Deployment Gn Labels can be attached to objects at creation time or later fn, They can be modified at any time, Let's expose our application now using a Service and apply some labels, Create a new Service Let’ verity th for existing Pods: ur application is running. Wellse the kubect1 get command and look keubectl get podsIfo Pods are running then it means the objects from the previous tutorials were cleaned Up. In this case, go back and recreate the deployment from the Using Kubect! to create a Deployment tutorial. Please wait a couple of seconds and list the Pods again. You can continue once you see the one Pad running. Next, let's list the current Services from our cluster: eubectl get services We have a Service called kubernetes that is created by default when minikube starts the cluster, To create a new service and expose it to external traffic well use the expose command with NodePort as parameter. kubectl expose deployment/kubernetes-bootcan --type="NodePort” --port Let's run again the get services subcommand: keubectl get services We have now a running Service called kubernetes-bootcamp. Here we see that the Service recelved a unique cluster-P, an internal port and an external1P (the IP of the Node), ‘To find out what port was opened externally (for the type: NodePart Service) we'llrun the describe service subcommand: eubectl describe services/kubernetes-bootearp Create an environment variable called NODE_PoRT that has the value of the Node port assigned! export NODE PORT="$(hubectt get services/kubernetes-bootcarp -o go-terplate="{{(index spec.ports @).nodePort)}")" 0E_PORT=SNOOE_PORT™ echo" Now we can test that the app is exposed outside of the cluster using curl , the IP address of the Node and the externally expased port: cunt neeps//"$(minikube 4p) :$N00E_PoRT™ Note: If Docker is the container runtime, a inikube tunnel Is needed. This is because Docker Desktop does not support ports, Ina separate terminal window, execute: $ minikube service kubernetes-booteanp --url ‘The output looks like this: Inttp:/7227.0.0.1:51082 | Because you are using 2 Docker driver on darwin, the tersinal needs to be open to run st. ‘Then use the given URL to access the app: $ curl 127.0.0.1:51082 ‘And we get a response from the server. The Service is exposed. Step 2: Using labels he Deployment created automaticaly a label for our Pod. With the deserve depioyent subcommand you can see the name (the key) of that labet eubectl describe deployment Let's use this label to query our lst of Pods. We'lluse the kubect1 get pods command with -1as a parameter, followed by the label values:hubect get pods -1 appskubernetes-bootcanp You can do the same to list the existing Services: subectl get services -1 appekubernetes-booteane Get the name of the Pod and store it in the POD_NANE environment variable: export Pon_MNES"S(kubectl get pods 0 go-tenplate --tenplate "{{range -{tens}} {metadata namey}C\W" P94 {en8))")° ‘echo "Nane of the Pod: $700_Nae To apply anew label we use the 1abel subcommand followed by the object type, object name and the new label ubectl Label pods “"$P00_NAME™ versioneva his will apply a new label to our Pod (we pinned the application version to the Pod}, and we can checkiit with the describe pod command: eubectl describe pods "$P00_NaMe We see here that the label is attached now to our Pod. And we can query now the list of pods using the new label eubeeth get pods -1 versioneva ‘And we see the Pod, Deleting a service ‘0 delete Services you can use the delete service Subcommand, Labels can be used also here: Confirm that the Service is gone: ‘This confirms chat our Service was removed. To confirm that ro anymore you can curl the previously exposed IP and port: Is not exposed cul he $(qintkube ip) :$N00#_poRT™ ‘This proves that the application is not reachable anymore from outside of the cluster. You can confirm that the app is still running with a cur from inside the pod: eubectl exec -ti $900_NINE -- curl hetp://localhost: We see here that the application is up. This is because the Deployment is managing the application. To shut down the application, you would need to delete the Deployment as, well ‘once you're ready, move on to Running Mulple Instances of Your App.5 - Scale Your App 5.1 - Running Multiple Instances of Your App Scale an existing app manually using kubectl Objectives © Scale an app using kubect Scaling an application Previous we created a Deployment andthen exposed SUMMary: publicly via a Service. The Deployment created only one + Scaling a Pod for running our application. When traffic increases, Deployment we wil need to scale the application to keep up with user demand. Ifyou haven't worked through the earlier sections, start from Using minikube to create a cluster. ‘Scoling is accomplished by changing the number of replicas in a Deployment NOTE If you are trying this after the previous section, you may need to start from creating a cluster as the services may have been deleted Scaling overview - ej (ee Zs Scaling out a Deployment will ensure new Pods are created and scheduled to Nodes with available resources. Scaling will increase the number of Pods to the new desired state. Kubernetes also supports autoscaling of Pods, but its outside ofthe scope of this tutorial. Scaling to zero is also possible, and it will erminate all Pods of the specified Deployment.Running multiple instances of an application will equire a way to distribute the traffic to all of them. Services have an integrated load-balancer that will distribute network traffic to all Pods of an exposed Deployment. Services will ‘monitor continuously the running Pods using endpoints, to ensure the trafic is sent only to available Pods. Once you have multiple instances of an application running, you would be able to do Rolling updates without downtime, Well cover that in the next section of the tutorial. Now, let's go to the terminal and scale our application, Scaling a Deployment Tolist your Deployments use the get deployments subcommand: kubectl get deployments ‘The output should be similar to: kubernetes-booteanp 11 1 un We should have 1 Pod. Ifnot, run the command again. This shows: ‘+ NAMElists the names of the Deployments in the cluster. + READY shows the ratio of CURRENT/DESIRED replicas + UP-TO-DATE displays the number of replicas that have been updated to achieve the desired state + AVAILABLE displays how many replicas of the application are available to your users. + AGE displays the amount of time that the application has been running. ‘see the ReplicaSet created by the Deployment, run babecth get rs Notice that the name of the ReplicaSet is always formatted as [DEPLOYMENT-NAME] = [RANOOM-STRING). The random string is randomly generated and uses the pod-remplate- hash as a seed. ‘wo important colurnns of this output are: * DESIRED displays the desired number of replicas ofthe application, which you define when you create the Deployment. This is the desired state + CURRENT aisplays how many replicas are currently running. Next, let's scale the Deployment to 4 replicas. Welluse the kubect1 scale command, followed by the Deployment type, name and desired number of instances: kubectl scale deploynents/kubernetes-booteanp --replicases Tolist your Deployments once again, use get deployrents kedbectl get deployments, ‘The change was applied, and we have 4 instances of the application available. Next, let's check if the number of Pods changed hubectl get pods -0 wide here are 4 Pods now, with different P addresses, The change was registered in the Deployment events log. To check that, use the describe subcommand kubectl describe deploynents/kubernetes-bootcanp You can also view in the output of this command that there are 4 replicas now.Load Balancing Let’s check that the Service is load-balancing the traffic. To find out the exposed IP and Port we can use the describe service as we learned in the previous part ofthe tutorial ubectl describe services/kubernetes-bootearp Create an environment variable called NooE_PoRT that has a value as the Node port: spec.ports @).nodePort)}")" ‘S(kubectt get services/kubernetes-bootcarp -o go-terplate="{{(index echo NODE_PORT=SNODE_PORT Next, we'll doa cunt to the exposed IP address and port. Execute the command multiple times: curl netps//"$(minikube 4p) :$N00E_PoRT™ We hit a different Pod with every request. This demonstrates that the load-balancing is working Scale Down To scale down the Deployment to 2 replicas, run again the scale subcommand: keubectl scale deploynents/kubernetes-bootcanp --replicase2 List the Deployments to checkif the change was applied with the get ceploynents subcommans: ubectl get deployments ‘The number of replicas decreased to 2. List the number of Pods, with get pods kabectl get pods -0 wide ‘This confirms that 2 Pods were terminated. ‘once you're ready, move on to Performing a Rolling Update,6 - Update Your App 6.1 - Performing a Rolling Update Perform a rolling update using kube Objectives + Perform a rolling update using kubect Updating an application Users expect applications to be available all the time and Summary: developers are expected to deploy new versions of them ‘+ Updating an several times a day. In Kubernetes this is done with raling app updates, Relling updates allow Deployments’ update to take place with zero downtime by incrementally updating Pods instances with new ones. The new Pods willbe scheduled on Nodes with available resources. Inthe previous module we scaled our application to run muliple instances. This is a requirement for performing updates without affecting application availablity. By default, the maximum number of Pods that can be Unavailable during the update and the maximum number of new Pods that can be created, is one, Both options can be configured to either numbers or percentages (of Pods). In Kubernetes, updates are versioned and any Deployment update can be reverted to a previous (stable) Rolling updates overview tee IC ee NU 4 Similar to application Scaling, fa Deployment is exposed publidly, the Service will load-balance the traffic only to available Pods during the update. An available Pod is an instance that is available to the users of the application. Rolling updates alow the following actions:+ Promote an application from one environment to another (via container image updates) + Rollback to previous versions ‘+ Continuous Integration and Continuous Delivery of applications with zero downtime In the following interactive tutorial, welll update our application to a new version, and also perform a rollback, Update the version of the app Tolist your Deployments, run the get ceployrents subcommand: kubect) get Tolist the running Pods, run the get pots subcommand: keubect get pods To view the current image version of the app, run the describe peds subcommand and look for the image field kubectl describe pods ‘To update the image ofthe application to version 2, use the set inage subcommand, followed by the deployment name and the new image version: kubectl set snage deployments /kubernetes-bootcanp Kubernetes boot canp=jocatalin/kubernetes-boot can ‘The command notified the Deployment to use a different image for your app and initiates a rolling update, Check the status of the new Pads, and view the ald one terminating with the get pods. subcommands Step 2: Verify an update First, check that the app is running. To find the exposed IP address and port, run the describe service command: ubecth describe services/kubernetes-bootearp Create an environment variable called NoDE_PoRT that has the value of the Node port assigned: export NODE_PORT="S(kubectt get services/kubernetes-bootcarp -o go-terplate="{{(index spec.ports ©).nodePort}}")" echo "NODE_PORT=$800E_PORT™ Next, doa curt to the exposed IP and port: cu ne $(minthube ip) :$u00e_port™ Every time you run the curl command, you willhita different Pod. Notice that all Pods are now running the latest version (v2), You can also confirm the update by running the roto status. subcommanc! hubectt rollout states ceploynents/hubernetes-boot camp To view the currentimage version ofthe app, run the describe pods subcommand! kabectl describe pods In the nage field ofthe output, verity that you are running the latest image version (v2) Roll back an update Let's perform another update, and try to deploy an image tagged with vieubectl set Anage deploynents/kubernetes-bootcanp kubernetes-bootcanp=gcr 10/o0gle- samples/tubernetes-bootearg:v20 Use get deploynents to see the status of the deployment keubectl get deployments, Notice that the output doesn’t st the desired number of available Pods. Run the et sods subcommand ta list al Pods: eubect get pods Notice that some of the Pads have a status of InagePul lBackorF ‘To get more insight into the problem, run the describe pods subcommands kubectl describe pods Inthe events section of the output for the affected Pods, notice that version did not exist in the repository, 1e vie image ‘orrollback the deployment to your last working version, use the rettout undo subcommand: eubectl rollout undo deploynents/kubernetes-bootcamp ‘The roLtout undo command reverts the deployment to the previous known state (v2 of the image). Updates are versioned and you can revert to any previously known state of a Deployment. Use the get pods subcommand to list the Pods again: keubect get pods Four Pods are running, To check the image deployed on these Pods, use the esentbe ubectl describe pods the Deployment is once again using a stable version ofthe app (42). The rollback was successful Remember to clean up your local cluster kubectl delete deployments/kubernetes-bootcanp services/tubernetes-bootcarp
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6132)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (935)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
k8s Module Ansible
PDF
No ratings yet
k8s Module Ansible
17 pages
Whyk 8 S
PDF
No ratings yet
Whyk 8 S
43 pages
k8s Arch Conn
PDF
No ratings yet
k8s Arch Conn
32 pages
K 8 S 1
PDF
No ratings yet
K 8 S 1
1 page
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)