Kubernetes 101: Excercise 2 for CKA (kubectl, pod, yaml file)


Following our journey on the preparation towards the exam CKA (Certified Kubernetes Administrator), we continue this time with the exercise number 2. 

Exercise 2:

  • create an nginx pod in a default namespace and verify that the pod is running 
  • delete the pod
  • create the same pod nginx with a yaml file
  • let's check the output of the yaml file of the pod you just created

Solution:

kubectl run nginx --image=nginix --restart=Never
kubectl get pods

Creating a pod

kubectl create -f nginx-pod.yaml
kubectl delete pod nginx
kubectl create -f nginx-pod.yaml
kubectl get po nginx -o yaml

#Output yaml file
kind: Pod
metadata:
  creationTimestamp: "2021-08-05T13:25:46Z"
  labels:
    run: nginx
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:conditions:
          .: {}
          k:{"type":"PodScheduled"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}            f:status: {}
            f:type: {}
    manager: kube-scheduler
    operation: Update
    time: "2021-08-05T13:25:46Z"
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:labels:
          .: {}
          f:run: {}
      f:spec:
        f:containers:
          k:{"name":"nginx"}:
            .: {}
            f:image: {}
            f:imagePullPolicy: {}
            f:name: {}
            f:resources: {}
            f:terminationMessagePath: {}
            f:terminationMessagePolicy: {}
        f:dnsPolicy: {}
        f:enableServiceLinks: {}
        f:restartPolicy: {}
        f:schedulerName: {}
        f:securityContext: {}
        f:terminationGracePeriodSeconds: {}
    manager: kubectl-create
    operation: Update
    time: "2021-08-05T13:25:46Z"
  name: nginx
  namespace: default
  resourceVersion: "8852"
  uid: d09254bf-48f7-432c-86c3-d9d29c921e74
spec:
  containers:
  - image: ngix
    imagePullPolicy: Always
    name: nginx
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-6zlwd
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Never
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-6zlwd
    secret:
      defaultMode: 420
      secretName: default-token-6zlwd
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2021-08-05T13:25:46Z"
    message: '0/1 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master:
      }, that the pod didn''t tolerate.'
    reason: Unschedulable
    status: "False"
    type: PodScheduled
  phase: Pending
  qosClass: BestEffort


Comments

Leave as a comment:

Archive