|
1 | 1 | --- |
2 | | -title: Kubernetes Lab 2 - Pod Configuration |
| 2 | +title: Kubernetes Lab 2 - Probes |
3 | 3 | --- |
4 | 4 |
|
5 | | -## Problem |
| 5 | +### Container Health Issues |
6 | 6 |
|
7 | | -- Create a pod definition named `yoda-service-pod.yml`, and then create a pod in the cluster using this definition to make sure it works. |
| 7 | +The first issue is caused by application instances entering an unhealthy state and responding to user requests with error messages. Unfortunately, this state does not cause the container to stop, so the Kubernetes cluster is not able to detect this state and restart the container. Luckily, the application has an internal endpoint that can be used to detect whether or not it is healthy. This endpoint is `/healthz` on port `8080`. |
8 | 8 |
|
9 | | -The specifications are as follows: |
| 9 | +- Your first task will be to *create a probe* to check this endpoint periodically. |
| 10 | + - If the endpoint returns an **error** or **fails** to respond, the probe will detect this and the cluster will restart the container. |
10 | 11 |
|
11 | | - - The current image for the container is `bitnami/nginx`. You do not need a custom command or args. |
12 | | - - There is some configuration data the container will need: |
13 | | - - `yoda.baby.power=100000000` |
14 | | - - `yoda.strength=10` |
15 | | - - It will expect to find this data in a file at `/etc/yoda-service/yoda.cfg`. Store the configuration data in a ConfigMap called `yoda-service-config` and provide it to the container as a mounted volume. |
16 | | - - The container should expect to use `64Mi` of memory and `250m` CPU (use resource requests). |
17 | | - - The container should be limited to `128Mi` of memory and `500m` CPU (use resource limits). |
18 | | - - The container needs access to a database password in order to authenticate with a backend database server. The password is `0penSh1ftRul3s!`. It should be stored as a Kubernetes secret called `yoda-db-password` and passed to the container as an *environment variable* called `DB_PASSWORD`. |
19 | | - - The container will need to access the Kubernetes API using the ServiceAccount `yoda-svc`. Create the service account if it doesn't already exist, and configure the pod to use it. |
| 12 | +### Container Startup Issues |
20 | 13 |
|
21 | | -## Verification |
| 14 | +Another issue is caused by new pods when they are starting up. The application takes a few seconds after startup before it is ready to service requests. As a result, some users are getting error message during this brief time. |
22 | 15 |
|
23 | | -To verify your setup is complete, check `/etc/yoda-service` for the `yoda.cfg` file and use the `cat` command to check it's contents. |
| 16 | + - To fix this, you will need to *create another probe*. To detect whether the application is `ready`, the probe should simply make a request to the root endpoint, *`/ready`, on port `8080`*. If this request succeeds, then the application is ready. |
24 | 17 |
|
| 18 | +- Also set a `initial delay` of `5 seconds` for the probes. |
| 19 | + |
| 20 | +Here is the Pod yaml file, **add** the probes, then **create** the pod in the cluster to test it. |
| 21 | + |
| 22 | +```yaml |
| 23 | +apiVersion: v1 |
| 24 | +kind: Pod |
| 25 | +metadata: |
| 26 | + name: energy-shield-service |
| 27 | +spec: |
| 28 | + containers: |
| 29 | + - name: energy-shield |
| 30 | + image: ibmcase/energy-shield:1 |
25 | 31 | ``` |
26 | | -kubectl exec -it yoda-service /bin/bash |
27 | | -cd /etc/yoda-service |
28 | | -cat yoda.cfg |
29 | | -``` |
|
0 commit comments