Sunday, May 13, 2018

Kubernetes - Pods

Pods
A Pod is a 1 or group of containers having same application running on any worker node. A Pod
is a collection of containers. The Pod name goes with the whale theme of docker containers,
since group of whales are called pod.

A pod can also be taught as  a smallest deployable artifact in a cluster. A Pod represents a
collection of application containers and volumes running in the same execution environment.
This means all containers defined inside the pod definition will land on the same execution
environment.

How is Pod created?
Kubectl command will use the yml file and connect to the kube-apiserver running on 6443.
This in turn will connect to the kube-controller-manager which will further connect to the
kube-scheduler. this scheduler program connects to worker nodes using kubelet agent and
then kubelet agent connects to docker daemon on the worker node and launch the container
based on the pod definition in the YML file

The applications running in the POD all use the same network namespace, IP address and Port
Space. They communicate with each other using the localhost.

Each POD will have an IP address and has full communication with other physical computers
across the network.

A simple POD is created using yml file. create a file POD.yml file and add the below contents as,
apiVersion: v1
kind: Pod
metadata:
 name: kube-pod-testing
 labels:
  app: pingpong-java
  region: IN
  rack: r1
  version: "1.1"
spec:
 containers:
   - name: web-server-test-container
     image: docker.io/rajpr01/myapp
     ports:
     - containerPort: 3000

In the above file kind, Name, image and containerPort are very important.
Kind - Type here it is Pod.
Name - name of the container
Image - Image of the container
containerPort - port that is being exposed to the outside from container.

Run the “kubectl create -f pod.yml” which will create a Pod.

Get the Pod details using the ,
[root@manja17-I13330 kubetesting]# kubectl get pods
NAME                  READY STATUS RESTARTS   AGE
kube-pod-testing   1/1 Running 0           1d

We can check resources for our running pod by,
[root@manja17-I13330 kubetesting]# kubectl describe  pod kube-pod-testing
Name:          kube-pod-testing
Namespace:    default
Node:          dev.foohost.vm/10.0.2.15
Start Time:   Fri, 20 Apr 2018 08:18:42 -0400
Labels:       app=pingpong-java
              rack=r1
              region=IN
              version=1.1
Annotations:  <none>
Status:       Running
IP:           10.44.0.1
Containers:
 web-server-test-container:
   Container ID:   docker://7934cb451aa73d727b34181b9ae78454c7304ad78d12eb7fac7c667e27
bdb618
   Image:          docker.io/rajpr01/myapp
   Image ID:     docker-pullable://docker.io/rajpr01/myapp@sha256:287844a655b8c205b
9099f8c258b5d6370f921a5953f652eeca64524576e45ea
   Port:           3000/TCP
   Host Port:      0/TCP
   State:          Running
     Started:      Fri, 20 Apr 2018 08:19:38 -0400
   Ready:          True
   Restart Count:  0
   Environment:    <none>
   Mounts:
     /var/run/secrets/kubernetes.io/serviceaccount from default-token-r4w74 (ro)
Conditions:
 Type           Status
 Initialized    True
 Ready          True
 PodScheduled   True
Volumes:
 default-token-r4w74:
   Type:        Secret (a volume populated by a Secret)
   SecretName:  default-token-r4w74
   Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>


Connecting to the Pod - Kubernetes allows us to login to the container using exec command similar
to the docker exec. The container names are generally assigned in the manifest file or we can get
the details when we describe the pod. we can connect to the pod using,
[root@manja17-I13330 kubenetes-config]# kubectl exec testing-service -c test-ser -it -- bash
root@testing-service:/usr/src/app# ls
Dockerfile  requirements.txt  testing_service.py
root@testing-service:/usr/src/app# exit

the syntax will be "kubectl exec <pod Name> -c <Container Name> -it -- bash". We can also run the commands with out logging into the container using,
[root@manja17-I13330 kubenetes-config]# kubectl exec testing-service -c test-ser free
             total used       free shared buffers     cached
Mem:       4046940 3758468     288472 61204 6368    2668700
-/+ buffers/cache:    1083400 2963540

Swap:            0 0     0


More to Come , Happy learning :-)

No comments :

Post a Comment