Cluster 1, Storage, olive-pvc-cka10-str
For this question, please set the context to cluster1 by running:
kubectl config use-context cluster1
We want to deploy a python based application on the cluster using a template located at /root/olive-app-cka10-str.yaml on student-node. However, before you proceed we need to make some modifications to the YAML file as per details given below:
- The YAML should also contain a persistent volume claim with name
olive-pvc-cka10-strto claim a100Miof storage fromolive-pv-cka10-str PV. - Update the deployment to add a sidecar container, which can use
busyboximage (you might need to add a sleep command for this container to keep it running.) - Share the
python-datavolume with this container and mount the same at path/usr/src. Make sure this container only hasreadpermissions on this volume. - Finally, create a pod using this YAML and make sure the POD is in
Runningstate.
Missing from the question, but required to pass
- Create a nodeport service for this deployment with the following specification
- Node port:
32006 - Name:
olive-svc-cka10-str
- Node port:
Solution
-
Examine what we have…
cat /root/olive-app-cka10-strThe PVC volume claim is already present. Look for the PVC
kubectl get pvcIt is not present, therefore it will have to be created first.
kubectl get pvThe PV exists. Note the
ACCESS MODESandSTORAGECLASS, which are required in the PVC manifest, along with the storage request given in the question. -
Prepare manfiest for the new PVC
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: olive-pvc-cka10-str spec: accessModes: - ReadWriteMany resources: requests: storage: 100Mi storageClassName: olive-stc-cka10-strThen create it. It will not bind yet until the pod is created.
-
Adjust the pod as directed, and add the service to the end.
apiVersion: apps/v1 kind: Deployment metadata: name: olive-app-cka10-str spec: replicas: 1 template: metadata: labels: app: olive-app-cka10-str spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - cluster1-node01 containers: - name: busybox image: busybox command: # <- Any variation of sleep command should work. - bin/sh # Needs to sleep long enough to get to end of test. - -c - sleep 10000 volumeMounts: - mountPath: /usr/src name: python-data readOnly: true - name: python image: poroko/flask-demo-app ports: - containerPort: 5000 volumeMounts: - name: python-data mountPath: /usr/share/ volumes: - name: python-data persistentVolumeClaim: claimName: olive-pvc-cka10-str selector: matchLabels: app: olive-app-cka10-str --- apiVersion: v1 kind: Service metadata: name: olive-svc-cka10-str namespace: default spec: ports: - nodePort: 32006 port: 5000 protocol: TCP targetPort: 5000 selector: app: olive-app-cka10-str type: NodePort -
Create the resources
kubectl apply -f /root/olive-app-cka10-str