17 November 2020

What is a Pod in Kubernetes world

PODs are mortal & is the smallest unit of deployment in K8s object mode or is like hosting a service.
Each pod can host different set of containers. The proxy is then used to control the exposing of these services to the outside world. You cannot create your own pods, they are created by replicasets or statefulsets. When ever a pod runs it calls a container image from registry(if not available locally) and deploy its container within it self. It can have more than one container.
  • each Pod has only 1 IP, irrespective of number of containers.
  • all container in a Pod shares IP, cgroups, namespaces, localhost adapter, volumes
  • every pod can interact directly with other pod via Pod N/W (Inter-Pod communication)
there are two types of communication in pods
  • Inter-pod
  • Intra-pod - every container in a pod can interact each other via shared localhost interface

    lets see how a pod manifest file look like to run in a cluster pod.yaml

    apiVersion: v1
    kind: Pod
      name: myapp
        zones: prod
        version: v1
      - name: app-container
        image: punitporwal07/myapp:0.1
        -  containerPort: 8000
    $ kubectl create -f pod.yaml
    $ kubectl get pods 
    $ kubectl describe pods (checks status)

    NOTE: we don't work directly on pods
    so we use replication controller to manage container inside a pod, which implements the desired state
    get your sample replcationController.yml

    Now big question is, how do we access our pods ? Service is the answer.
    1. accessing outside the cluster (Browser, client)
    2. accessing inside the cluster (How Pods interact with each other)
    services nail both the above

    every service gets a name and IP which are STABLE! which means name and this IP will never change throughout its life.
    services are REST objects in K8s, service stands infront of Pod so that outside world can interact to Pods via service. service never change mean its IP, DNS, Ports are reliable, unlike Pods which are unreliable in nature.

    Service use Labels to identify the Pods and do the things on them.
    now since pods are mortal and they come and go, so how do service identify which pods are alive. so Its Endpoint which maintains the list of available pods dynamically and let service know about the active pods.

    accessing replication controller pod and exposing it to a different Port (create/get/describe)

    kubectl create -f svc.yml
    kubectl get svc 
    kubectl describe svc -myapp-svc
    $ kubectl expose rc myapp-rc --name=myapp-svc --taget-port=8000 --type=NodePort (this way it will expose the service hello-svc)
    $ kubectl describe svc myapp-svc (describes the service with all its meaningful attributes like port, Namespace, labels etc.)

    K8S Deployments:
    Deployment is about updates and rollbacks this is the superset of replication controller and can access deployment via node pod service

    for example deployment.yml may look like

    apiVersion: extensions/v1beta1
    kind: Deployment
      name: myapp-deploy
      replicas: 5
            app: prod
          - name: myapp-container
            image: punitporwal07/myapp:0.1
            -  containerPort: 8000

    at last be declarative!
    kubectl create -f <manifest.yaml>
    check in to source control > make changes to same file > apply change with 
    $ kubectl apply --record 


    No comments:

    Post a Comment