k8s.github.io

Mock Exam 1

Test My Knowledge, Take me to Mock Exam 1

#### Solution to the Mock Exam 1

  1. Apply below manifests:

    ``` apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: nginx-pod name: nginx-pod spec: containers: - image: nginx:alpine name: nginx-pod resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {} ```
  2. Run below command which create a pod with labels:

    ``` kubectl run messaging --image=redis:alpine --labels=tier=msg ```
  3. Run below command to create a namespace:

    ``` kubectl create namespace apx-x9984574 ```
  4. Use the below command which will redirect the o/p:

    ``` kubectl get nodes -o json > /opt/outputs/nodes-z3444kd9.json ```
  5. Execute below command which will expose the pod on port 6379:

    ``` kubectl expose pod messaging --port=6379 --name messaging-service ```
  6. Apply below manifests:

    ``` apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: hr-web-app name: hr-web-app spec: replicas: 2 selector: matchLabels: app: hr-web-app strategy: {} template: metadata: creationTimestamp: null labels: app: hr-web-app spec: containers: - image: kodekloud/webapp-color name: webapp-color resources: {} status: {} ``` In v1.19, we can add `--replicas` flag with `kubectl create deployment` command: ``` kubectl create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2 ```
  7. To Create a static pod, copy it to the static pods directory. In this case, it is /etc/kubernetes/manifests. Apply below manifests:

    ``` apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: static-busybox name: static-busybox spec: containers: - command: - sleep - "1000" image: busybox name: static-busybox resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {} ```
  8. Run below command to create a pod in namespace finance:

    ``` kubectl run temp-bus --image=redis:alpine -n finance ```
  9. Run below command and troubleshoot step by step:

    ``` kubectl describe pod orange ``` Export the running pod using below command and correct the spelling of the command **`sleeeep`** to **`sleep`** ``` kubectl get pod orange -o yaml > orange.yaml ``` Delete the running Orange pod and recreate the pod using command. ``` kubectl delete pod orange kubectl create -f orange.yaml ```
  10. Apply below manifests:

    ``` apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: app: hr-web-app name: hr-web-app-service spec: ports: - port: 8080 protocol: TCP targetPort: 8080 nodePort: 30082 selector: app: hr-web-app type: NodePort status: loadBalancer: {} ```
  11. Run the below command to redirect the o/p:

    ``` kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os_x43kj56.txt ```
  12. Apply the below manifest to create a PV:

    ``` apiVersion: v1 kind: PersistentVolume metadata: name: pv-analytics spec: capacity: storage: 100Mi volumeMode: Filesystem accessModes: - ReadWriteMany hostPath: path: /pv/data-analytics ```