You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Your Name e9da09d5f4 Push k8s training 3 months ago
..
README.md Push k8s training 3 months ago
index.html Push k8s training 3 months ago
pod.yaml Push k8s training 3 months ago

README.md

A simple web application

You will manipulate pods and configmaps in order to deploy a microservice in kubernetes.

1. Declare a pod

Complete the following Pod manifest in order to deploy an nginx container with an empty volume attached to
/usr/share/nginx/html.

# To create: kubectl apply -f pod.yaml
---
apiVersion: v1
kind: Pod
metadata:
  name: simple-pod-nginx
  labels:
    exo: simple-pod
spec:
  volumes:
  - emptyDir: {}
    name: html
  containers: {} # TODO

You can review the results through various kubectl commands.
# Describe resources and show event logs from Kubernetes controllers
kubectl describe pod/simple-pod-nginx

# Get brief of a pod
kubectl get pod/simple-pod-nginx

# Get brief of resources filtered by label in the yaml format
kubectl get all -l "exo=simple-pod" -o yaml

# Get a specific field value from a resource (here the pod's IP)
kubectl get pod/simple-pod-nginx -o jsonpath='{.status.podIP}'

You can also print the logs from the containered application.

kubectl logs pod/simple-pod-nginx

2. Acces the nginx service

By default, the nginx service is listening on port 80. If not already done, you should expose the container port in the pod declaration (see pod.spec.containers.ports).

Then it can be accessed by forwarding your localhost:8080 to the pod's port.

kubectl port-forward pod/simple-pod 8080:80

Surprisingly, the web page shows an error 403.

Can you hypothesize on why it occurred ? Maybe using the application logs.


However we notice that the pod is in a ready state and contradicts the real state of our application.

NAME                   READY   STATUS    RESTARTS   AGE
pod/simple-pod-nginx   1/1     Running   0          1m

3. Evaluate the readiness of a container

Try to add a readinessProbe to your container definition that leaves the pod in an unready state until the web page is answering with a 200 response code.

4. Fix the web page

You should update the web content by uploading the index.html to the container web root.

kubectl cp can be quite handy

The page should now display correctly and the pod should hop in a ready state. However while its okay to use cp in some cases, here changes won't persist after the pod's lifetime.

5. Storing configuration data

A ConfigMap is a very handy resource that can hold configuration data for an application.

You can use the CLI and kubectl create to generate the configuration from the index.html file.

Also you can choose to adjust the following manifest :

apiVersion: v1
kind: ConfigMap
metadata:
  name: simple-pod-html
data: {}

Finaly modify the pod declaration in order to mount this configmap at /usr/share/nginx/html.

The application should serve its html content from the configmap and it will allow the configuration to survive reboots.