docker_advanced_k8s_deploy_pod_deployment

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docker_advanced_k8s_deploy_pod_deployment [2020/05/01 14:47] andonovjdocker_advanced_k8s_deploy_pod_deployment [2020/05/01 16:54] (current) andonovj
Line 9: Line 9:
 So let's see how it behaves as a VM and a Container: So let's see how it behaves as a VM and a Container:
  
-=====Network=====+====Network====
 As we already mentioned, the atomic unit of scheduling in Kubernetes is the Pod, if we want to grow, we add pods, NOT containers. As we already mentioned, the atomic unit of scheduling in Kubernetes is the Pod, if we want to grow, we add pods, NOT containers.
 So, how these pods communicate with the outside world. Well, each pod has its own IP. So, how these pods communicate with the outside world. Well, each pod has its own IP.
Line 20: Line 20:
  
 ===InterPod Communication=== ===InterPod Communication===
-{{:interpodcommunication.jpg?400|}}+This is the communication between different pods: 
 + 
 +{{:interpodcommunication.jpg?600|}}
  
 ===IntraPod Communication=== ===IntraPod Communication===
-{{:intrapodcommunication.jpg?400|}}+This is the communication between different containers within the same pod. Rarely you will see more than one container in a pod, BUT it is possible.
  
-=====Lifecycle=====+{{:intrapodcommunication.jpg?300|}} 
 + 
 +====Lifecycle====
 The lifecycle of a pod is the following: The lifecycle of a pod is the following:
  
Line 36: Line 40:
 Here is a picture for visual reference of the above : Here is a picture for visual reference of the above :
  
-{{:podsoverview.jpg?600|}}+{{:podsoverview.jpg?700|}} 
 + 
 +=====Deployment===== 
 +So let's get going, our first order of business is creating a manifest file, so let's use the same app which we dockerized on the docker section:  
 + 
 +  * andonovj/httpserverdemo:latest 
 + 
 + 
 +====Manifest file==== 
 +The manifest file can be YML or JSON, up to you, I have went with the YML because I hate myself :) It is very simple, but working. 
 + 
 +<Code:bash|Manifest file> 
 +apiVersion: v1 
 +kind: Pod 
 +metadata: 
 +  name: date-pod 
 +  labels: 
 +    zone: prod 
 +    version: v1 
 +spec: 
 +  containers: 
 +  - name: hello-ctr 
 +    image: andonovj/httpserverdemo:latest 
 +    ports: 
 +    - containerPort: 8080 
 +</Code> 
 + 
 +So what this YML is telling the API server: 
 +  - We name our pod: "date-pod" as it shows the current date 
 +  - We put it two labels, first that it is a prod and second that it is version 1 
 +  - WE name our container: "Hello-ctr" 
 +  - We use the image from the docker repo: "andonovj/httpserverdemo:latest" 
 +  - WE define port 8080 for connection. 
 + 
 +So let's create it :) 
 + 
 +====Create the Pod==== 
 +The creation of the pod is done using the kubectl and using the YML file (in my case pod.yml) 
 + 
 +<Code:bash|Create Pod> 
 +ubuntu@k8s-master:~$ kubectl create -f pod.yml 
 +pod/date-pod created 
 +ubuntu@k8s-master:~$ kubectl get pods 
 +NAME       READY   STATUS              RESTARTS   AGE 
 +date-pod   0/    ContainerCreating            17s 
 +</Code> 
 + 
 +===Describe a pod=== 
 +Now, it says that it is ContinerCreating mode, but that is more of explanation of why it is in Pending state than a status. 
 +We can check a more detailed status using again kubectl, but with the describe option: 
 + 
 +<Code:bash|Describe a pod> 
 +ubuntu@k8s-master:~$ kubectl describe pods 
 +Name:         date-pod 
 +Namespace:    default 
 +Priority:     0 
 +Node:         node-2/10.0.2.15 
 +Start Time:   Fri, 01 May 2020 15:41:40 +0000 
 +Labels:       version=v1 
 +              zone=prod 
 +Annotations:  cni.projectcalico.org/podIP: 192.168.247.1/32 
 +Status:       Running 
 +IP:           192.168.247.1 
 +IPs: 
 +  IP:  192.168.247.1 
 +Containers: 
 +  hello-ctr: 
 +    Container ID:   docker://0709a53a0b8b3d05830ae6a08976ef50df520229b1e37fe08809d53e31e5e489 
 +    Image:          andonovj/httpserverdemo:latest 
 +    Image ID:       docker-pullable://andonovj/httpserverdemo@sha256:5e0866ff45e12c8e350923fbe32d94bd76bd2d1576722d4d55ca786043bfcbe1 
 +    Port:           8080/TCP 
 +    Host Port:      0/TCP 
 +    State:          Running 
 +      Started:      Fri, 01 May 2020 15:42:05 +0000 
 +    Ready:          True 
 +    Restart Count: 
 +    Environment:    <none> 
 +    Mounts: 
 +      /var/run/secrets/kubernetes.io/serviceaccount from default-token-jc2sg (ro) 
 +Conditions: 
 +  Type              Status 
 +  Initialized       True 
 +  Ready             True 
 +  ContainersReady   True 
 +  PodScheduled      True 
 +Volumes: 
 +  default-token-jc2sg: 
 +    Type:        Secret (a volume populated by a Secret) 
 +    SecretName:  default-token-jc2sg 
 +    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: 
 +  Type    Reason     Age        From               Message 
 +  ----    ------     ----       ----               ------- 
 +  Normal  Scheduled  <unknown>  default-scheduler  Successfully assigned default/date-pod to node-2 
 +  Normal  Pulling    42s        kubelet, node-2    Pulling image "andonovj/httpserverdemo:latest" 
 +  Normal  Pulled     21s        kubelet, node-2    Successfully pulled image "andonovj/httpserverdemo:latest" 
 +  Normal  Created    21s        kubelet, node-2    Created container hello-ctr 
 +  Normal  Started    21s        kubelet, node-2    Started container hello-ctr 
 +</Code> 
 + 
 +Congrats, that was your first manual pod deployment. 
 + 
 +====Check the Container=== 
 +So we know that a pod runs one, in some cases more, container(s).  
 +We can check our servers, in my case, it was on the 2nd Worker: 
 + 
 +<Code:Bash|Check the container> 
 +root@node-2:~# docker container ls 
 +CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS               NAMES 
 +0709a53a0b8b        andonovj/httpserverdemo   "dotnet HttpServerDe…"   25 minutes ago      Up 25 minutes                           k8s_hello-ctr_date-pod_default_2445c62d-2329-40ba-b026-e2c98031366c_0 
 +root@node-2:~# 
 +</Code> 
 + 
 +So we have 1 requested image running and 1 is running on the 2nd worker. 
 +What if we want to delete a pod. Well very simple: 
 + 
 +====Delete a pod==== 
 +To delete a pod, again use the kubectl command as follows: 
 + 
 +<Code:Bash|Delete a pod> 
 +ubuntu@k8s-master:~$ kubectl get pods 
 +NAME       READY   STATUS    RESTARTS   AGE 
 +date-pod   1/    Running            38m 
 +ubuntu@k8s-master:~$ kubectl delete pod date-pod 
 +pod "date-pod" deleted 
 +ubuntu@k8s-master:~$ 
 +</Code> 
 + 
 +But what if we want to have more security and load balancing. Let's say, what if we want 5 replica of that pod. Well, that is for the replication controller which we will discsuss in the next section.
  • docker_advanced_k8s_deploy_pod_deployment.1588344438.txt.gz
  • Last modified: 2020/05/01 14:47
  • by andonovj