kubernetes in action 2nd edition release date

For example, if your Kubernetes cluster runs on Amazons AWS EC2, you can use an awsElasticBlockStore volume. Youll need to have Docker installed for that, so lets learn how it fits into the container story. What if the application cant detect this? Later in the book youll learn how to limit the CPU time and total memory available to a container. Figure 6.5 Exponential back-off between container restarts In the worst case, a container can therefore be prevented from starting for up to five minutes. You can now access the fortune service at http://localhost:1080/quote. In cases where the command completes successfully, the output of the command is not logged anywhere. It limits, accounts for and isolates system resources such as CPU, memory and disk or network bandwidth. STAT Sl Ss R+ START 12:31 12:31 12:38 TIME 0:00 0:00 0:00 COMMAND node app.js bash ps aux Manning Publications Co. To comment go to liveBook 49 The list shows only three processes. NOTE Exit code 128+n indicates that the process exited due to external signal n. Exit code 137 is 128+9, where 9 represents the KILL signal. Immediately thereafter, Kubernetes restarts the container and the pods status returns to Running. After that youll explore the inner workings of Kubernetes components. As part of my work at Red Hat, I started using Kubernetes in 2014, even before version 1.0 was released. The following listing shows how youd configure the startup and the liveness probes. To see an example of a post-start hook that fails, deploy the pod manifest fortune-poststart-fail.yaml. The pod needs some sort of secret token to authenticate against this system. Youll create the pod from the YAML shown in the following listing. Kubectl, the Kubernetes command-line tool, is pronounced kube-control. Its clear that you need automation, and at this massive scale, it better be perfect. As the following figure shows, they run one after the other and must all finish successfully before the main containers of the pod are started. This includes things like: service discovery - a mechanism that allows applications to find other applications and use the services they provide, horizontal scaling - replicating your application to adjust to fluctuations in load, load-balancing - distributing load across all the application replicas, self-healing - keeping the system healthy by automatically restarting failed applications and moving them to healthy nodes after their nodes fail, leader election - a mechanism that decides which instance of the application should be active while the others remain idle but ready to take over if the active instance fails. This way, you get the best of both worlds. When you create a new process, you can specify which namespace it should use. Listing 2.5 Listing locally stored images $ docker images REPOSITORY TAG kubia latest IMAGE ID b0ecc49d7a1d CREATED 1 minute ago VIRTUAL SIZE 908 MB UNDERSTANDING HOW THE IMAGE WAS BUILT Figure 2.11 shows what happens during the build process. The regions are listed at services/. This is an online version of the Manning book Kubernetes in Action, 2nd . Some are shared with other processes, while others are not. This includes retrieving certificates and private keys used by the main container from secure certificate stores, generating config files, downloading data, and so on. This is especially useful when a volume contains sensitive information that should only be accessible to some containers. In contrast to the phase, a pod has several conditions at the same time. This ensures that the data will be written to the persistent disk. If you use PowerShell, execute set-alias -name k -value kubectl. 3.1.5 Creating a cluster using Amazon Elastic Kubernetes Service If you prefer to use Amazon instead of Google to deploy your Kubernetes cluster in the cloud, you can try the Amazon Elastic Kubernetes Service (EKS). In special cases where an external system must be notified when a new instance of the application is started, an init container can be used to deliver this notification. For this you would need a VM to emulate the x86 architecture. Youve already learned how to do this, but you may want to refer to the sidebar because there is a caveat. But as the microservices become smaller and their numbers start to grow, you may not be able to afford to give each one its own VM if you want to keep your hardware costs low and not waste resources. You can make the liveness probe succeed again by clicking the healthcheck/ok button in Envoys admin interface, or by using curl as follows: $ curl -X POST localhost:9901/healthcheck/ok Manning Publications Co. To comment go to liveBook 156 If you are fast enough, the container wont be restarted. A very popular software package that can provide this functionality is Envoy. Figure 6.6 The configuration and operation of a liveness probe The parameter initialDelaySeconds determines how long Kubernetes should delay the execution of the first probe after starting the container. Fortunately, Kubernetes hides these details. #B The IP of the NFS server #C The path exported by the server NOTE Although Kubernetes supports nfs volumes, the operating system running on the worker nodes provisioned by Minikube or kind might not support mounting nfs volumes. In the next chapter, youll learn how to abstract the underlying storage technology away from the pod manifest and make the manifest portable to any other Kubernetes cluster. So even if you have a broken application that runs out of memory after running for more than a few hours, Kubernetes will ensure that your application continues to provide the service to its users by automatically restarting it in this case. UNDERSTANDING HOW NAMESPACES ISOLATE PROCESSES FROM EACH OTHER By creating a dedicated namespace instance for all available namespace types and assigning it to a process, you can make the process believe that its running in its own OS. To the two processes, it looks as if they run on two different computers. The control plane then triggers the other components to do whatever needs to be done based on the changes you made via the API. But if your system consists of less than five microservices, throwing Kubernetes into the mix is probably not a good idea. INTRODUCING THE DELETION GRACE PERIOD The termination of each container at pod shutdown follows the same sequence as when the container is terminated because it has failed its liveness probe, except that instead of the termination grace period, the pods deletion grace period determines how much time is available to the containers to shut down on their own. You can choose a name other than kubia if you wish. )JVz{fgw="`U?xG0|Si+N'31l((/2Q pHdP:j1 SkoL[!74h)>OQhhe@cs,]8$\|Jl;3?t9XF~mh6:mf5:)VY+ F/&>c,[\s|fK&IXZtYU&-t jU,|:=!jM Rs 12:22 0:00 ps aux #B #A The Node.js server #B The command youve just invoked This is the Kubernetes equivalent of the Docker command you used to explore the processes in a running container in chapter 2. If your infrastructure has enough free resources to allow normal system operation without the failed node, the operations team doesnt even have to react immediately to the failure. In chapter 9, youll learn how to use the Downward API to inject the name of the pod into an environment variable. Building the fortune container image You need two files to build the image. Why it is necessary to use the --insecure option There are two reasons why you must use the --insecure option when accessing the service. AppArmor is similar but uses file paths instead of labels and focuses on processes rather than users. The following listing shows the definition of this pre-stop hook. This is typically the place where applications write their logs. 2.3.3 Limiting a process resource usage with Linux Control Groups Linux Namespaces make it possible for processes to access only some of the hosts resources, but they dont limit how much of a single resource each process can consume. Two pods are still running. GETTING THE PODS IP ADDRESS You can get the pods IP address by retrieving the pods full YAML and searching for the podIP field in the status section. The startup probe can be configured to take into account the slow start of the application. ADDING A TCPSOCKET LIVENESS PROBE For applications that accept non-HTTP TCP connections, a tcpSocket liveness probe can be configured. If it runs macOS or Windows, the daemon and the containers run in the Linux VM. First, lets determine the pods IP address. The file system of the container originates from the container image, but additional file systems can also be mounted into the container. They run these containers on thousands of computers distributed across dozens of data centers around the world. The --ssh-access flag used in the command that creates the cluster ensures that your SSH public key is imported to the node. Fortunately, you can specify a list of ports in the pod definition itself. If this is not the case in your cluster, you should read section 5.4 to learn how to troubleshoot pod failures. What if all the containers in a pod die? This can be problematic if the process doesnt start up immediately. If the probe receives a response, and the response code doesnt represent an error (in other words, if the HTTP response code is 2xx or 3xx), the probe is considered successful. This applies to all kubectl options that take a Boolean value and default to false. Create the file in the same directory as the app.js file and make sure it contains the three directives in the following listing. An in-depth look at the components and their internals follows in the third part of the book. If youre already familiar with a particular storage technology, you should be able to use the explain command to easily find out how to configure the correct volume type. In fact, you should never run multiple applications in the same container, as this makes managing the processes in the container much more difficult. This way, you never run out of space to run additional instances of your applications. If the locally cached image matches the one in the registry, it is not downloaded again, but the registry still needs to be contacted. The --dry-run=client flag tells kubectl to output the definition instead of actually creating the object via the API. INSPECTING THE PODS CONDITIONS To see the conditions of a pod, you can use kubectl describe as in the next listing: Listing 6.1 Displaying a pods conditions using kubectl describe $ kubectl describe po kubia | grep Conditions: -A5 Conditions: Type Status Initialized True #A Ready True #B ContainersReady True #B PodScheduled True #C #A The pod has been initialized #B The pod and its containers are ready #C The pod has been scheduled to a node The kubectl describe command only shows whether each condition is true or not. Enabling billing. The next time, however, Kubernetes waits ten seconds before restarting it again. To find out why a condition is false, you must inspect the pod manifest, as shown in the next listing. Port 1234 on the host computer is mapped to port 8080 in the container (specified by the -p 1234:8080 option), so you can access the app at http://localhost:1234. The following listing shows the commands output. To display the logs of the network-check container in the kubia-init pod, run the command shown in the following listing. 1.1 Introducing Kubernetes The word Kubernetes is Greek for pilot or helmsman, the person who steers the ship - the person standing at the helm (the ships wheel). This repository contains all the code (and some additional files) from the Kubernetes in Action, 2nd Edition book. It has a single binary executable file, which youll find in the Minikube repository on GitHub (http://github.com/kubernetes/minikube). ADDING AN EMPTYDIR VOLUME TO THE FORTUNE POD Lets change the definition of the fortune pod so that the post-start hook writes the file to the volume instead of to the ephemeral filesystem of the container. Not many people working in the software industry knew about Kubernetes, and there was no real community yet. The pods status is displayed as either NotReady or CrashLoopBackOff. If you are an experienced systems administrator, you may be able to do it without much pain and suffering, but most people may want to try one of the methods described in the previous sections first. The Envoy proxy handles the task perfectly. While Kubernetes reduces long-term operational costs, introducing Kubernetes in your organization initially involves increased costs for training, hiring new engineers, building and purchasing new tools and possibly additional hardware. ABOUT THE KUBE PROXY Because an application deployment can consist of multiple application instances, a load balancer is required to expose them at a single IP address. In this case, kubectl logs will only display the new log file. You run a shell inside the container. The fortune pod currently serves the same quote throughout the lifetime of the pod. NOTE You can specify multiple object types in the delete command. ABOUT THE CONTROLLERS Most object types have an associated controller. Because the fortune command is not available in the image, youd normally build a new image based on the Nginx image and install the fortune package during the container build process. The command shown in the listing installs some packages onto the images filesystem. Like VMs, but with much less overhead. Refer to https://cloud.google.com/compute/docs/regions-zones to see the list of available locations. For now, youll use an image that already contains all three files. Figure 1.6 Comparing monolithic applications with microservices Manning Publications Co. To comment go to liveBook 7 Each microservice is now a separate application with its own development and release cycle. While each VM usually runs its own set of system processes, which requires additional computing resources in addition to those consumed by the user applications own process, a container is nothing more than an isolated process running in the existing host OS that consumes only the resources the app consumes. In the next chapter, youll learn about the lifecycle of the pod and its containers. Just restarting the container and using the same corrupted files could result in an endless crash loop. 2022 Simon & Schuster, Inc. All rights reserved. You cant see the other processes that run in the host OS or in other containers because the container runs in its own Process ID namespace. The -- all option indicates that you want to delete all instances of each object type. Nowadays, youll rarely see the fortune command installed on Unix/Linux systems anymore, but you can still install it and run it whenever youre bored. Even if you deploy microservices, using Kubernetes may not be the best option, especially if the number of your microservices is very small. If youre using kind, create the pod from the file mongodbpod-hostpath-kind.yaml, which ensures that the pod is always deployed on the same node. This makes kind the perfect tool for development and testing, as everything runs locally and you can debug running processes as easily as when you run them outside of a container. In such cases, instead of adding a pre-stop hook to send the TERM signal to your app, the correct solution is to use the exec form of ENTRYPOINT or CMD. Now lets take a closer look at the entire lifecycle of a pod and its containers. The init-demo container is started first. Once youve successfully deployed one or two clusters using kubeadm, you can then try to deploy it completely manually, by following Kelsey Hightowers Kubernetes the Hard Way tutorial at github.com/kelseyhightower/Kubernetes-the-hard-way. Attach to your kubia pod by running the following command: $ kubectl attach kubia Defaulting container name to kubia. Instead of using a gitRepo volume, it is recommended to use an emptyDir volume and initialize it using an init container. NOTE The same as with liveness probes, lifecycle hooks can only be applied to regular containers and not to init containers. Your IP is ::ffff:127.0.0.1. Figure 6.7 The exec liveness probe runs the command inside the container The following listing shows an example of a probe that runs /usr/bin/healthcheck every two seconds to determine if the application running in the container is still alive. field indicates the time at which this container was started. They are typically accompanied by storage volumes that allow a pods containers to store data for the lifetime of the pod or beyond, or to share files with the other containers of the pod. rj_~^8}GE'I wo"B>brOgONWsn^. Since each container has its own writable layer, changes to shared files are not visible in any other container. UNDERSTANDING WHAT HAPPENS WHEN YOU RUN A CONTAINER Figure 2.10 shows exactly what happened when you executed the docker run command. Make sure that you configure it to use Linux containers. 6.4 Understanding the pod lifecycle So far in this chapter youve learned a lot about how the containers in a pod run. You can use the exec type of the hook to execute an additional process as the main process starts, or you can use the httpGet hook to send an HTTP request to the application running in the container to perform some type of initialization or warm-up procedure. Manning Publications Co. To comment go to liveBook 2 How to pronounce Kubernetes and what is k8s? A pods status section contains the following information: the IP addresses of the pod and the worker node that hosts it when the pod was started the pods quality-of-service (QoS) class what phase the pod is in, the conditions of the pod, and the state of its individual containers. As a software developer, your primary focus is on implementing the business logic. If the application doesnt respond, an error occurs, or the response is negative, the container is considered unhealthy and is terminated. The benefits usually outweigh the disadvantages. You can do everything with a single docker run command, by specifying the image to download and the command to run in it. USING KUBECTL ATTACH TO WRITE TO THE APPLICATIONS STANDARD INPUT The kubia application doesnt read from the standard input stream, but youll find another version of the application that does this in the books code archive. To build and push the image you can also run the following command in the Chapter07/ directory: $ PREFIX=luksa/ PUSH=true ./build-fortune-writer-image.sh Again, replace luksa/ with your Docker Hub user ID. SHARING FILES BETWEEN MULTIPLE CONTAINERS A volume can be mounted in more than one container so that applications running in these containers can share files. Manning Publications Co. To comment go to liveBook 142 6 Managing the lifecycle of the Pods containers This chapter covers Inspecting the pods status Keeping containers healthy using liveness probes Using lifecycle hooks to perform actions at container startup and shutdown Understanding the complete lifecycle of the pod and its containers After reading the previous chapter, you should be able to deploy, inspect and communicate with pods containing one or more containers. Choosing a base image You may wonder why use this specific image as your base. 5.5 Running additional containers at pod startup When a pod contains more than one container, all the containers are started in parallel. The correct Greek pronunciation of Kubernetes, which is Kie-ver-nee-tees, is different from the English pronunciation you normally hear in technical conversations.

Sitemap 1

kubernetes in action 2nd edition release date

This site uses Akismet to reduce spam. rustic chalk paint furniture ideas.