/final

Test John Bryce

John Bryce Final Project

Part one:

Question 1: Deploy a pod named nginx-pod using the nginx:alpine image. Name: nginx-pod-yourname Image: nginx:alpine.

Solution: image

Question 2: Deploy a messaging pod using the redis:alpine image with the labels set to tier=msg. Pod Name: messaging Image: redis:alpine Labels: tier=msg

Solution: image

Question 3: Create a namespace named apx-x998-yourname

Solution: image

Question 4: Get the list of nodes in JSON format and store it in a file at /tmp/nodes-yourname

Solution: image

Question 5: Create a service messaging-service to expose the messaging application within the cluster on port 6379. a. Use imperative commands - kubectl b. Service: messaging-service c. Port: 6379 d. Type: ClusterIp e. Use the right labels

Solution: image

Question 6: Same question as question 5.

Question 7: Create a deployment named hr-web-app using the image kodekloud/webapp-color with 2 replicas a. Name: hr-web-app b. Image: kodekloud/webapp-color c. Replicas: 2

Solution: image

Question 8: Create a static pod named static-busybox on the master node that uses the busybox image and the command sleep 1000 a. Name: static-busybox b. Image: busybox c. Replicas: 2

Solution: image

Qutestion 9: Create a POD in the finance-yourname namespace named temp-bus with the image redis:alpine a. Name: temp-bus b. Image Name: redis:alpine

Solution: Creating the namespace: image

Creating a pod with the namespace:

image

Question 10: Create a Persistent Volume with the given specification a. Volume Name: pv-analytics b. Storage: 100Mi c. Access modes: ReadWriteMany d. Host Path: /pv/data-analytics

Solution: image

Check that it's created successfully:

image

PV YAML File(pv-volume.yaml) here - https://github.com/sagzig/final/blob/main/pv-volume.yaml PV-Claim YAML File(pv-claim.yaml) here- https://github.com/sagzig/final/blob/main/pv-claim.yaml

Question 11: Create a Pod called redis-storage-yourname with image: redis:alpine with a Volume of type emptyDir that lasts for the life of the Pod. specs: a. Pod named 'redis-storage-yourname' b. Pod 'redis-storage-yourname' uses Volume type of emptyDir c. Pod 'redis-storage-yourname' uses volumeMount with mountPath = /data/redis

Solution:

image

Create pod YAML File(pv-pod-new.yaml) here - https://github.com/sagzig/final/blob/main/pv-pod-new.yaml

Question 12: Create this pod and attached it a persistent volume called pv-1 a. Make sure the PV mountPath is hostbase : /data

Solution:

Creating a persistent volume: image

Creating a pod and attaching the pv to it: image

Create pod file (createpod.yaml) here- https://github.com/sagzig/final/blob/main/createpod.yaml Create volume file (createvol.yaml) here- https://github.com/sagzig/final/blob/main/createvol.yaml

Question 13: Create a new deployment called nginx-deploy, with image nginx:1.16 and 1 replica. Record the version. Next upgrade the deployment to version 1.17 using rolling update. Make sure that the version upgrade is recorded in the resource annotation. a. Deployment : nginx-deploy. Image: nginx:1.16 b. Image: nginx:1.16 c. Task: Upgrade the version of the deployment to 1:17 d. Task: Record the changes for the image upgrade

Solution: image

Question 14: Create an nginx pod called nginx-resolver using image nginx, expose it internally with a service called nginx-resolver-service. Test that you are able to look up the service and pod names from within the cluster. Use the image: busybox:1.28 for dns lookup. Record results in /root/nginx-yourname.svc and /root/nginx-yourname.pod

Solution: image

Createing a service File(createservice-q14.yaml) here- https://github.com/sagzig/final/blob/main/createaservice-q14.yaml

Question 15: Create a static pod on node01 called nginx-critical with image nginx. Create this pod on node01 and make sure that it is recreated/restarted automatically in case of a failure.

Solution:

Question 16: Create a pod called multi-pod with two containers. Container 1, name: alpha, image: nginx Container 2: beta, image: busybox, command sleep 4800. a. Environment Variables: i. container 1: ii. name: alpha iii. Container 2: iv. name: beta

Solution: image

Pod creation YAML File(multipod.yaml) here - https://github.com/sagzig/final/blob/main/multipod.yaml


Part 2

Question 1: Type the command for: Get pods with label information

Solution: kubectl get pods --show-labels

Question 2: Create 5 nginx pods in which two of them is labeled env=prod and three of them is labeled env=dev

Creation of 2 pods labeled env=prod YAML File(2pods.yaml) here- https://github.com/sagzig/final/blob/main/2pods.yaml Creation of 3 pods labeled env=dev YAML File(3pods.yaml) here- https://github.com/sagzig/final/blob/main/3pods.yaml

Question 3: Verify all the pods are created with correct labels

Solution: image

Question 4: Get the pods with label env=dev

Solution: image

Question 5: Get the pods with label env=dev and also output the labels

Solution: image

Question 6: Get the pods with label env=prod

Solution: image

Question 7: Get the pods with label env=prod and also output the labels

Solution: image

Question 8: Get the pods with label env

Solution: image

Question 9: Get the pods with labels env=dev and env=prod

Solution: image

Question 10: Get the pods with labels env=dev and env=prod and output the labels as well

Solution: image

Question 11: Change the label for one of the pod to env=uat and list all the pods to verify

Solution: image

Question 12: Remove the labels for the pods that we created now and verify all the labels are removed

Solution: image

Question 13: Let’s add the label app=nginx for all the pods and verify (using kubectl)

Solution: image

Question 14: Get all the nodes with labels (if using minikube you would get only master node)

Solution: image

Question 15: Label the worker node nodeName=nginxnode

Solution: image

Question 16: Create a Pod that will be deployed on the worker node with the label nodeName=nginxnode

Solution: image

Create a pod YAML File(question16.yaml) here- https://github.com/sagzig/final/blob/main/question16.yaml

Question 17: Verify the pod that it is scheduled with the node selector on the right node... fix it if it’s not behind scheduled.

Solution: image

Question 18: Verify the pod nginx that we just created has this label

Solution: image


Part 3

Question 1: Create a deployment called webapp with image nginx with 5 replicas a. Use the below command to create a yaml file. i. kubectl create deploy webapp --image=nginx --dry-run -o yaml > webapp.yaml ii. Edit it and add 5 replica’s

Solution:

1.a: Editing the file

image

1.b:

Checking replicas added

image

Question 2: Get the deployment rollout status

Solution: image

Question 3: Get the replicaset that created with this deployment

Solution: image

Question 4: EXPORT the yaml of the replicaset and pods of this deployment

Solution: YAML File of the replicaset here - https://github.com/sagzig/final/blob/main/replicaset.yaml YAML File of the Pods here - https://github.com/sagzig/final/blob/main/exportpods.yaml

Question 5: Delete the deployment you just created and watch all the pods are also being deleted

Solution: image

Question 6: Create a deployment of webapp with image nginx:1.17.1 with container port 80 and verify the image version a. kubectl create deploy webapp --image=nginx:1.17.1 --dry-run -o yaml > webapp.yaml b. add the port section (80) and create the deployment

Solution:

6.a: Building the configuration and editing the file: image

6.b: Running the file after editing and verifying the port 80 attached: image

Question 7: Update the deployment with the image version 1.17.4 and verify

Solution: image

Question 8: Check the rollout history and make sure everything is ok after the update

Solution: image

Question 9: Undo the deployment to the previous version 1.17.1 and verify Image has the previous version

Solution: image

Question 10: Update the deployment with the wrong image version 1.100 and verify something is wrong with the deployment a. Expect: kubectl get pods (ImagePullErr) b. Undo the deployment with the previous version and verify everything is Ok c. kubectl rollout history deploy webapp --revision=7 d. Check the history of the specific revision of that deployment e. update the deployment with the image version latest and check the history and verify nothing is going on

Solution:

10.a: image

10.b: image

10.c: image

10.d: image

10.e: image

Question 11: Apply the autoscaling to this deployment with minimum 10 and maximum 20 replicas and target CPU of 85% and verify hpa is created and replicas are increased to 10 from 1

Solution: image

Question 12: This question does not exists

Question 13: Clean the cluster by deleting deployment and hpa you just created

Solution: image

Question 14: Create a job and make it run 10 times one after one (run > exit > run >exit ..) using the following configuration: kubectl create job hello-job --image=busybox --dry-run -o yaml -- echo "Hello I am from job" > hello-job.yaml” a. Add to the above job completions: 10 inside the yaml

Solution: Editing the file and edditng the "completion:10" into it:

image


Part 4

Question 1: Create a file called config.txt with two values key1=value1 and key2=value2 and verify the file

Solution: I ran the given commands and received the file: image

Question 2: Create a configmap named keyvalcfgmap and read data from the file config.txt and verify that configmap is created correctly

Solution: Creating the ConfigMap: image

Question 3: Create an nginx pod and load environment values from the above configmap keyvalcfgmap and exec into the pod and verify the environment variables and delete the pod // first run this command to save the pod yml kubectl run nginx --image=nginx --restart=Never --dry-run -o yaml > nginx-pod.yml

Solution: Editing the given file: image

Running the file and checking that it's built with the ConfigMap: image

The File(nginx-pod) used to created to pod after editing, here- https://github.com/sagzig/final/blob/main/nginx-pod.yml