This scenario demonstrates the Predictable Demands pattern from Kubernetes Patterns.
This pattern is about how you should declare application requirements, whether they are hard runtime dependencies or resource requirements. Declaring your requirements is essential for Kubernetes to find the right place for your application within the cluster.
After this scenario you know
- how to detect that a hard runtime requirement like a ConfigMap is missing
- how define resources limits for CPU and Memory
- what happens when these limits are selected too low
In this scenario you learned about two ways how you can communicate application requirements to Kubernetes:
- By specifying your runtime dependencies like a ConfigMap reference. Another example would be the dependency on a PersistentVolume (which we do not have shown here)
- By setting CPU and Memory requests and limits.
Create a Pod with runtime requirements
While you are reading this we are starting a simple single node Kubernetes cluster for you. Please be patient and wait until the
launch.sh script has finished.
Let's create a simple Pod which references a non-existing ConfigMap
The Pod itself is a simple REST service which just returns a freshly generated random number each time it is called.
pod.yml you find the definition of a bare Pod which references a ConfigMap for being used as environment variables.
Check the content of this declaration with
Let's create now that Pod with
kubectl create -f pod.yml
and watch how it starts up:
kubectl get pods -w
(you can stop this with CTRL-C).
Eventually you will see how the Pod goes into the status
This is also reported with
kubectl describe pod random-generator
As you can see, that Pod won't start because the hard runtime requirement of a ConfigMap is missing.
In the next step we will add this missing requirement.