Creating a pod

kubectl run day5 --image nginx

Getting info about pod:

kubectl get pod day5 -oyaml

Whatever mentioned in the spec section that’s what the pod is going to do.

ImagePullPolicy: Official docs

apiVersion: v1                           # API version for the Pod definition
kind: Pod                                # Defines the object type as a Pod
metadata:                                # Metadata about the pod
  annotations:                           # Custom metadata annotations
    cni.projectcalico.org/containerID:    # Container ID for network plugin (Calico)
    cni.projectcalico.org/podIP:          # Pod's IP address
    cni.projectcalico.org/podIPs:         # List of pod IPs (single IP in this case)
  creationTimestamp: "2024-10-20T13:14:46Z" # Time when the pod was created
  labels:                                # Key-value pairs for identifying the pod
    run: day5                            # A label named 'run' with value 'day5'
  name: day5                             # Name of the pod
  namespace: default                     # Namespace where the pod is running
  resourceVersion: "2363"                # Version of the pod resource for updates
  uid: e1144b8f-1595-47a0-ab6d-676f2c93ab0c # Unique ID for the pod
spec:                                    # Pod specification
  containers:                            # List of containers within the pod
  - image: nginx                         # Image to be used (nginx)
    imagePullPolicy: Always              # Always pull the latest image
    name: day5                           # Container name
    resources: {}                        # No resource limits specified
    terminationMessagePath: /dev/termination-log # Path for termination messages
    terminationMessagePolicy: File       # Use a file for termination messages
    volumeMounts:                        # List of volumes mounted in the container
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount # Mount path for the service account token
      name: kube-api-access-tn9nc         # Volume name
      readOnly: true                      # The volume is read-only
  dnsPolicy: ClusterFirst                # Use cluster's DNS for name resolution
  enableServiceLinks: true               # Allows service environment variables
  nodeName: node01                       # Node where the pod is running
  preemptionPolicy: PreemptLowerPriority # Preempt lower-priority pods if needed
  priority: 0                            # Pod's priority (0 = lowest)
  restartPolicy: Always                  # Always restart the pod on failure
  schedulerName: default-scheduler       # Scheduler to use (default)
  securityContext: {}                    # Security settings (empty in this case)
  serviceAccount: default                # Service account name
  serviceAccountName: default            # Same as service account
  terminationGracePeriodSeconds: 30      # Grace period before forcefully killing the pod
  tolerations:                           # Conditions under which the pod is tolerated
  - effect: NoExecute                    # Effect if the condition is met
    key: node.kubernetes.io/not-ready    # Tolerate 'not-ready' condition
    operator: Exists                     # Tolerate if the key exists
    tolerationSeconds: 300               # For 300 seconds
  - effect: NoExecute                    # Same effect for 'unreachable' condition
    key: node.kubernetes.io/unreachable  # Tolerate 'unreachable' condition
    operator: Exists                     # Tolerate if the key exists
    tolerationSeconds: 300               # For 300 seconds
  volumes:                               # Volumes defined for the pod
  - name: kube-api-access-tn9nc           # Volume name
    projected:                           # Projected volume with multiple sources
      defaultMode: 420                   # File permissions for the volume
      sources:                           # Sources for the volume
      - serviceAccountToken:             # Service account token for accessing API
          expirationSeconds: 3607        # Token expiration time in seconds
          path: token                    # Path for the token
      - configMap:                       # Use ConfigMap for the CA certificate
          items:                         # Specific items to mount
          - key: ca.crt                  # CA certificate key
            path: ca.crt                 # Path where it will be mounted
          name: kube-root-ca.crt         # Name of the ConfigMap
      - downwardAPI:                     # Access downward API for pod metadata
          items:                         # Items from the downward API
          - fieldRef:                    # Reference to a field
              apiVersion: v1             # API version of the field
              fieldPath: metadata.namespace # Path to the namespace metadata
            path: namespace              # Mount path for the namespace info
status:                                  # Current status of the pod
  conditions:                            # List of pod conditions
  - lastProbeTime: null                  # Last time condition was probed (null)
    lastTransitionTime: "2024-10-20T13:14:53Z" # Last time condition transitioned
    status: "True"                       # Condition is true
    type: PodReadyToStartContainers      # Condition type: Ready to start containers
  - lastProbeTime: null                  # Same as above
    lastTransitionTime: "2024-10-20T13:14:46Z" # Transition time for initialization
    status: "True"                       # Initialization is complete
    type: Initialized                    # Condition type: Initialized
  - lastProbeTime: null                  # Same as above
    lastTransitionTime: "2024-10-20T13:14:53Z" # Transition time for readiness
    status: "True"                       # Pod is ready
    type: Ready                          # Condition type: Ready
  - lastProbeTime: null                  # Same as above
    lastTransitionTime: "2024-10-20T13:14:53Z" # Time when containers became ready
    status: "True"                       # Containers are ready
    type: ContainersReady                # Condition type: ContainersReady
  - lastProbeTime: null                  # Same as above
    lastTransitionTime: "2024-10-20T13:14:46Z" # Scheduled time for the pod
    status: "True"                       # Pod is scheduled
    type: PodScheduled                   # Condition type: PodScheduled
  containerStatuses:                     # Status of the containers in the pod
  - containerID: containerd://e5f98717eff0ad0038a4c5d9bfcedf206b3ef45b5bba9639183203ad04e9c438 # Container ID
    image: docker.io/library/nginx:latest # Image used by the container
    imageID: docker.io/library/nginx@sha256:28402db69fec7c17e179ea87882667f1e054391138f77ffaf0c3eb388efc3ffb # Image hash
    lastState: {}                        # Last known state (empty in this case)
    name: day5                           # Container name
    ready: true                          # Container is ready
    restartCount: 0                      # Number of restarts (none in this case)
    started: true                        # Container has started
    state:                               # Current state of the container
      running:                           # Container is running
        startedAt: "2024-10-20T13:14:53Z" # Time when the container started
    volumeMounts:                        # Volume mounts for the container
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount # Service account mount
      name: kube-api-access-tn9nc         # Volume name
      readOnly: true                      # Read-only access
      recursiveReadOnly: Disabled         # Recursive read-only is disabled
  hostIP: 172.30.2.2                     # IP address of the host node
  hostIPs:                               # List of IPs for the host node
  - ip: 172.30.2.2                       # Host IP
  phase: Running                         # Current phase of the pod (Running)
  podIP: 192.168.1.4                     # Pod's IP address
  podIPs:                                # List of pod IPs
  - ip: 192.168.1.4                      # Pod's IP
  qosClass: BestEffort                   # QoS class (BestEffort)
  startTime: "2024-10-20T13:14:46Z"      # Time when the pod started

Labels-Selectors & more in K8s

Labels are key-value pair, if you don’t add labels kubernetes by default will add it.


Question: What if you don’t add the label then what will be the key-value of that lable?

Ans: The key will be run and value will be the name of the pod like in thiese way:

run: <pod-name>