DevOps Classroomnotes 08/Sep/2023

Pods

  • This is atomic unit of k8s. Refer Here for official docs
  • Pod is collection of Containers.
    • Container in which we have application running is referred as main car and other are referred as side cars
      Preview

Creating Pod Manifests

  • The basic skeleton manifest which is suitable for majority of resources
---
apiVersion:
kind:
metadata:
spec:
  • This when executed becomes 5 as k8s will add status
---
apiVersion:
kind:
metadata:
spec:
status:
# if the apiGroup is not core
apiVersion: <apiGroup>/<version>

# if the apiGroup is core
apiVersion: <version>
  • To fill the rest lets use api reference Refer Here and for v1.28 the url will https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/ and if you are using 1.26 https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/
    Preview
  • Metdata: This helps in naming and labelling resources in k8s
  • Lets create a manifest to run nginx pod
---
apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
spec:
  containers:
    - name: webserver
      image: nginx:1.25
  • apply and execute the following commands
    Preview
  • When we execute kubectl get pod hello-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"hello-pod","namespace":"default"},"spec":{"containers":[{"image":"nginx:1.25","name":"webserver"}]}}
  creationTimestamp: "2023-09-08T03:31:01Z"
  name: hello-pod
  namespace: default
  resourceVersion: "7456"
  uid: 0706d91c-ce00-46ed-9238-4e5ea08e01eb
spec:
  containers:
  - image: nginx:1.25
    imagePullPolicy: IfNotPresent
    name: webserver
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-wwf5g
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: ip-172-31-13-24
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  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: kube-api-access-wwf5g
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2023-09-08T03:31:01Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2023-09-08T03:31:03Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2023-09-08T03:31:03Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2023-09-08T03:31:01Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://c913e6b88bb596c4af3a62ca70da835bbac71d6042df68a5ca9a7f528727a48e
    image: nginx:1.25
    imageID: docker-pullable://nginx@sha256:6926dd802f40e5e7257fded83e0d8030039642e4e10c4a98a6478e9c6fe06153
    lastState: {}
    name: webserver
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2023-09-08T03:31:03Z"
  hostIP: 172.31.13.24
  phase: Running
  podIP: 10.244.2.3
  podIPs:
  - ip: 10.244.2.3
  qosClass: BestEffort
  startTime: "2023-09-08T03:31:01Z"

Additional info

  • Kubernetes allows us to view all the resources using kubectl
kubectl api-resources

Preview
* Each Name refers a resource that can be manipulated by api-server. Each resource has name and short name
* kubernetes allows us to create resources imperatively as well declaratively
* Imperative means constructing a command

kubectl run nginx --image nginx

Preview
* Declartive: Create a yaml file with below content and execute kubectl apply -f <filename.yaml> to create and kubectl delete -f <filename.yaml> to delete

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner