Chapter 17. Best practices for developing apps

 

This chapter covers

  • Understanding which Kubernetes resources appear in a typical application
  • Adding post-start and pre-stop pod lifecycle hooks
  • Properly terminating an app without breaking client requests
  • Making apps easy to manage in Kubernetes
  • Using init containers in a pod
  • Developing locally with Minikube

We’ve now covered most of what you need to know to run your apps in Kubernetes. We’ve explored what each individual resource does and how it’s used. Now we’ll see how to combine them in a typical application running on Kubernetes. We’ll also look at how to make an application run smoothly. After all, that’s the whole point of using Kubernetes, isn’t it?

Hopefully, this chapter will help to clear up any misunderstandings and explain things that weren’t explained clearly yet. Along the way, we’ll also introduce a few additional concepts that haven’t been mentioned up to this point.

17.1. Bringing everything together

Let’s start by looking at what an actual application consists of. This will also give you a chance to see if you remember everything you’ve learned so far and look at the big picture. Figure 17.1 shows the Kubernetes components used in a typical application.

Figure 17.1. Resources in a typical application

17.2. Understanding the pod’s lifecycle

17.2.1. Applications must expect to be killed and relocated

17.2.2. Rescheduling of dead or partially dead pods

17.2.3. Starting pods in a specific order

17.2.4. Adding lifecycle hooks

17.2.5. Understanding pod shutdown

17.3. Ensuring all client requests are handled properly

17.3.1. Preventing broken client connections when a pod is starting up

17.3.2. Preventing broken connections during pod shut-down

17.4. Making your apps easy to run and manage in Kubernetes

17.4.1. Making manageable container images

17.4.2. Properly tagging your images and using imagePullPolicy wisely

17.4.3. Using multi-dimensional instead of single-dimensional labels

17.4.4. Describing each resource through annotations

17.4.5. Providing information on why the process terminated

17.4.6. Handling application logs

17.5. Best practices for development and testing

17.5.1. Running apps outside of Kubernetes during development

17.5.2. Using Minikube in development

17.5.3. Versioning and auto-deploying resource manifests

sitemap