Kubernetes Lab Solutions
Solutions
- apiVersion: v1kind: Podmetadata:name: nginxnamespace: webspec:containers:- name: nginximage: nginx
- apiVersion: v1kind: ConfigMapmetadata:name: yoda-service-configdata:yoda.cfg: |-yoda.baby.power=100000000yoda.strength=10apiVersion: v1kind: Secretmetadata:name: yoda-db-passwordstringData:password: 0penSh1ftRul3s!apiVersion: v1kind: Podmetadata:name: yoda-servicespec:serviceAccountName: yoda-svccontainers:- name: yoda-serviceimage: bitnami/nginx
- apiVersion: v1kind: ConfigMapmetadata:name: vader-service-ambassador-configdata:haproxy.cfg: |-globaldaemonmaxconn 256apiVersion: v1kind: Podmetadata:name: vader-servicespec:containers:- name: millennium-falconimage: ibmcase/millennium-falcon:1- name: haproxy-ambassadorapiVersion: v1kind: Podmetadata:name: busyboxspec:containers:- name: myapp-containerimage: radial/busyboxplus:curlcommand: ['sh', '-c', 'while true; do sleep 3600; done']
Check it with
kubectl exec busybox -- curl $(kubectl get pod vader-service -o=jsonpath='{.status.podIP}'):80 - apiVersion: v1kind: Podmetadata:name: energy-shield-servicespec:containers:- name: energy-shieldimage: ibmcase/energy-shield:1livenessProbe:
Check
STATUS
column for not Readykubectl get pods --all-namespacesCheck the description of the deployment
kubectl describe deployment hyper-driveSave logs for broken pod
kubectl logs <pod name> -n <namespace> > /home/cloud_user/debug/broken-pod-logs.logIn the deployment’s description you will see the following is wrong:
- Selector and Label names do not match.
- The Probe is TCP instead of HTTP Get.
- The Service Port is 80 instead of 8080.
kubectl get deployment <deployment name> -n <namespace> -o yaml --export > hyper-drive.ymlDelete pod
kubectl delete deployment <deployment name> -n <namespace>Edit yaml, and apply
kubectl apply -f hyper-drive.yml -n <namespace>Verify
kubectl get deployment <deployment name> -n <namespace>Update the deployment to the new version like so:
kubectl set image deployment/jedi-deployment jedi-ws=bitnamy/nginx:1.18.1 --recordCheck the progress of the rolling update:
kubectl rollout status deployment/jedi-deploymentIn another terminal window
kubectl get pods -wGet a list of previous revisions.
kubectl rollout history deployment/jedi-deploymentUndo the last revision.
kubectl rollout undo deployment/jedi-deploymentCheck the status of the rollout.
kubectl rollout status deployment/jedi-deployment- apiVersion: batch/v1beta1kind: CronJobmetadata:name: xwing-cronjobspec:schedule: "*/1 * * * *"jobTemplate:spec:template:kubectl get cronjob xwing-cronjob
- apiVersion: v1kind: Servicemetadata:name: jedi-svcspec:type: NodePortselector:app: jediports:apiVersion: v1kind: Servicemetadata:name: yoda-svcspec:type: ClusterIPselector:app: yodaports:
- apiVersion: v1kind: PersistentVolumemetadata:name: postgresql-pvspec:storageClassName: localdiskcapacity:storage: 1GiaccessModes:apiVersion: v1kind: PersistentVolumeClaimmetadata:name: postgresql-pv-claimspec:storageClassName: localdiskaccessModes:- ReadWriteOnceresources:apiVersion: v1kind: Podmetadata:name: postgresql-podspec:containers:- name: postgresqlimage: bitnami/postgresqlports: