KodeKloud Challenges: Kubernetes Challenge 2
Check KodeKloud’s Kubernetes Challenge #2!
Note - if you really must see the solutions directly, find them on my GitHub page; okbobm!
What’s the scenario? This 2-Node Kubernetes cluster is broken! Troubleshoot, fix the cluster issues and then deploy the objects according to the given architecture diagram to unlock our Image Gallery!
What are the general requirements for this challenge?
- Fix controlplane issues
- Fix node issues
- Populate web directory
- Create persistent volume (i.e. data-pv)
- Create persistent volume claim (i.e. data-pvc)
- Create pod (i.e. gop-file-server)
- Create service (i.e. gop-fs-service)
Step 1: Fix controlplane issues
Requirements:
- Master node: coredns deployment has image: ‘registry.k8s.io/coredns/coredns:v1.8.6’
- Fix kube-apiserver. Make sure its running and healthy.
- kubeconfig = /root/.kube/config, User = ‘kubernetes-admin’ Cluster: Server Port = ‘6443’
Solution:
- Fix issues with port:
- Note - this must be done first to use kubectl to interact with the deployment
- kubectl config set-cluster kubernetes –server=https://controlplane:6443
- Fix kube-apiserver. Make sure its running and healthy:
- Check out /etc/kubernetes/manifests/kube-apiserver.yaml to find any issues
- Note: “ca-athority” cert (in /etc/kubernetes/pki) doesn’t exist
- Change:
- client-ca-file=/etc/kubernetes/pki/ca-authority.crt
- client-ca-file=/etc/kubernetes/pki/ca.crt
- Check if apiserver is running: watch crictl ps
- If APIServer doesn’t come back, restart with: systemctl restart kubelet
- Master node: coredns deployment has image: ‘registry.k8s.io/coredns/coredns:v1.8.6’
- Check out image used in deployment:
- k edit deploy coredns -n kube-system
- The image is incorrect and needs to be changed:
- Within file, Modify image value to: registry.k8s.io/coredns/coredns:v1.8.6
- Check out image used in deployment:
Step 2: Fix node issues
Requirements:
- node01 is ready and can schedule pods?
Solution:
- Review the node for issues:
- k get nodes node1
- After review - node01 is available, but scheduling is disabled. Need to uncordon this node:
- k uncordon node01
Step 3: Populate web directory
Requirements:
- Copy all images from the directory ‘/media’ on the controlplane node to ‘/web’ directory on node01
Solution:
- scp /media/* node01:/web
Step 4: Create persistent volume (i.e. data-pv)
Requirements:
- Create new PersistentVolume = ‘data-pv’
- PersistentVolume = data-pv, accessModes = ‘ReadWriteMany’
- PersistentVolume = data-pv, hostPath = ‘/web’
- PersistentVolume = data-pv, storage = ‘1Gi’ite’.
Solution:
- Create a yaml file for the persistent volume
- Apply from yaml
- k apply -f pv.yaml
Step 5: Create persistent volume claim (i.e. data-pvc)
Requirements:
- Create new PersistentVolumeClaim = ‘data-pvc’
- PersistentVolume = ‘data-pvc’, accessModes = ‘ReadWriteMany’
- PersistentVolume = ‘data-pvc’, storage request = ‘1Gi’
- PersistentVolume = ‘data-pvc’, volumeName = ‘data-pv’
Solution:
- Create a yaml file for the persistent volume claim
- Apply from yaml
- k apply -f pvc.yaml
Step 6: Create pod (i.e. gop-file-server)
Requirements:
- Create a pod for file server, name: ‘gop-file-server’
- pod: gop-file-server image: ‘kodekloud/fileserver’
- pod: gop-file-server mountPath: ‘/web’
- pod: gop-file-server volumeMount name: ‘data-store’
- pod: gop-file-server persistent volume name: data-store
- pod: gop-file-server persistent volume claim used: ‘data-pvc’
Solution:
- Create a yaml file for the pod
- Apply from yaml
- k apply -f pod.yaml
Step 7: Create service (i.e. gop-fs-service)
Requirements:
- New Service, name: ‘gop-fs-service’
- Service name: gop-fs-service, port: ‘8080’
- Service name: gop-fs-service, targetPort: ‘8080’
Solution:
- Create a yaml file for the service
- Apply from yaml
- k apply -f service.yaml
Finally - completed!
You should see everything in green as in the diagram below:
Future bonus points: write a script to complete all the scripts at once!
(Find something in error or that could be done better? Contact me! I would love to hear from you.)