Skip to main content

PODS, SERVICES & DEPLOYMENTS

PODS

Pod is a wrapper to container and it is the smallest deployable unit in Kubernetes.

pod yaml configuration


 










Pod Useful Commands:

$kubectl version --short
Client Version: v1.22.4
Server Version: v1.22.4

$kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1                    <none>           443/TCP   5d20h

$kubectl get nodes
NAME             STATUS   ROLES                       AGE     VERSION
docker-desktop   Ready    control-plane,master   3d23h   v1.22.4

$kubectl cluster-info
Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

$kubectl cluster-info dump


$kubectl apply -f pod.yml
pod/hello-pod created


$kubectl get pods
NAME        READY   STATUS    RESTARTS   AGE
hello-pod       1/1         Running             0          9m26s

$kubectl get pods  --watch
NAME        READY   STATUS    RESTARTS   AGE
hello-pod       1/1          Running           0          9m31s

$kubectl get pods  -o wide
NAME        READY   STATUS    RESTARTS   AGE           IP               NODE                NOMINATED NODE   READINESS GATES
hello-pod   1/1     Running              0          11m   10.1.0.10     docker-desktop        <none>                          <none>

$kubectl describe pod hello-pod
Name:         hello-pod
Namespace:    default
Priority:     0
Node:         docker-desktop/192.168.65.4
Start Time:   Wed, 22 Dec 2021 18:41:10 +0530
Labels:       app=web
Annotations:  <none>
Status:       Running
IP:           10.1.0.10
IPs:
  IP:  10.1.0.10
Containers:
  deepu-daya:
    Container ID:   docker://2bd3de09d663b358ce5e220cbad225ed0944de08497b5eb11319a917115bfbad
    Image:          dayananda/deepu-daya:1.0
    Image ID:       docker-pullable://dayananda/deepu-daya@sha256:d7eb67f2c1a4484d72752c1f126bfb72a940af95e25396da718644cbb5b71cf1
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 22 Dec 2021 18:41:11 +0530
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9mj7g (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-9mj7g:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  13m   default-scheduler  Successfully assigned default/hello-pod to docker-desktop
  Normal  Pulled     13m   kubelet            Container image "dayananda/deepu-daya:1.0" already present on machine
  Normal  Created    13m   kubelet            Created container deepu-daya
  Normal  Started    13m   kubelet            Started container deepu-daya


$kubectl delete -f pod.yml
pod "hello-pod" deleted

$kubectl delete pod/<pod> or $kubectl delete pod <pod>


$kubectl get pod hello-pod --watch
NAME          READY    STATUS     RESTARTS   AGE
hello-pod      1/1        Running             0          91m

$kubectl get pods -A --watch
NAMESPACE         NAME                                                                   READY   STATUS      RESTARTS          AGE
default                 hello-pod                                                                  1/1       Running           0                 92m
kube-system       coredns-78fcd69978-9q8gq                                  1/1         Running   1 (3d ago)        5d17h
kube-system       coredns-78fcd69978-kx7pm                                 1/1     Running   1 (3d ago)        5d17h
kube-system       etcd-docker-desktop                                              1/1     Running   1 (3d ago)        5d17h
kube-system       kube-apiserver-docker-desktop                           1/1     Running   1 (3d ago)        5d17h
kube-system       kube-controller-manager-docker-desktop         1/1     Running   1 (3d ago)        5d17h
kube-system       kube-proxy-l4z7f                                                     1/1     Running   1 (3d ago)        5d17h
kube-system       kube-scheduler-docker-desktop                          1/1     Running   17 (2m57s ago)    5d17h
kube-system       storage-provisioner                                                1/1     Running   33 (2m57s ago)    5d17h
kube-system       vpnkit-controller                                                     1/1     Running   141 (2m49s ago)   5d17h


Create a pod from an image:
$Kubectl run hello-pod2  --image=dayananda/deepu-daya:1.0
pod/hello-pod2 created

Executing commands inside a pod:
$kubectl exec -it hello-pod2 -- ls
bin   dev  home  lib64  mnt  proc  run   src  sys  usr
boot  etc  lib   media  opt  root  sbin  srv  tmp  var

Interactive way
$kubectl run -i --tty nginx --image=nginx -- sh

Dry-run : without creating a pod
$kubectl run hello-po3 --image=nginx --dry-run
W1223 09:33:44.902118   27860 helpers.go:555] --dry-run is deprecated and can be replaced with --dry-run=client.
pod/hello-po3 created (dry run)

Patch a pod:
Kubectl patch pod <pod> -p '<patch>'

Example:
Kubectl patch pod <pod> -p '{"spec":{"containers":[{"name" : "patch-pod", "image" : "nginx"}]}}'



Get pod logs:
$kubectl logs <pod> or kubectl logs -f <pod>


Get containers inside a pod:
$kubectl get pods hello-pod -o jsonpath='{.spec.containers[*].name}'
'deepu-daya'

Kubectl top pod <pod-name>



Services:

Service spec configuration:





































































$kubectl expose pod hello-pod  --name=hello-svc --target-port=8080 --type=NodePort
service/hello-svc exposed

$kubectl get svc
NAME              TYPE             CLUSTER-IP     EXTERNAL-IP   PORT(S)                    AGE
hello-svc        NodePort      10.111.5.253   <none>            8080:30760/TCP   73s
kubernetes   ClusterIP        10.96.0.1      <none>               443/TCP                  5d20h

$kubectl describe service ps-nodeport
Name:                     ps-nodeport
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=web
Type:                          NodePort
IP Family Policy:         SingleStack
IP Families:                  IPv4
IP:                                10.107.77.195
IPs:                               10.107.77.195
LoadBalancer Ingress: localhost
Port:                                 <unset>  80/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  31111/TCP
Endpoints:                10.1.0.11:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>


Kubectl delete service <service_name>


Deployments:


















kubectl get deploy
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
web-deploy   0/5     5            0           14s


kubectl get rs
NAME                    DESIRED   CURRENT   READY   AGE
web-deploy-566bd8fc84   5         5         4       36s


kubectl get pod
NAME                          READY   STATUS    RESTARTS   AGE
web-deploy-566bd8fc84-4pncz   1/1     Running   0          55s
web-deploy-566bd8fc84-8zln2   1/1     Running   0          55s
web-deploy-566bd8fc84-967r8   1/1     Running   0          55s
web-deploy-566bd8fc84-cqz82   1/1     Running   0          55s
web-deploy-566bd8fc84-zvxzl   1/1     Running   0          55s


kubectl get pods --show-labels
NAME                          READY   STATUS    RESTARTS   AGE     LABELS
web-deploy-566bd8fc84-4pncz   1/1     Running   0          3m21s   app=web,pod-template-hash=566bd8fc84
web-deploy-566bd8fc84-8zln2   1/1     Running   0          3m21s   app=web,pod-template-hash=566bd8fc84
web-deploy-566bd8fc84-967r8   1/1     Running   0          3m21s   app=web,pod-template-hash=566bd8fc84
web-deploy-566bd8fc84-cqz82   1/1     Running   0          3m21s   app=web,pod-template-hash=566bd8fc84
web-deploy-566bd8fc84-zvxzl   1/1     Running   0          3m21s   app=web,pod-template-hash=566bd8fc84


kubectl get ep
NAME         ENDPOINTS           AGE
kubernetes   192.168.65.4:6443   6d17h


kubectl get ep
NAME         ENDPOINTS           AGE
kubernetes   192.168.65.4:6443   6d17h

kubectl describe ep
Name:         kubernetes
Namespace:    default
Labels:       endpointslice.kubernetes.io/skip-mirror=true
Annotations:  <none>
Subsets:
  Addresses:          192.168.65.4
  NotReadyAddresses:  <none>
  Ports:
    Name   Port  Protocol
    ----   ----  --------
    https  6443  TCP

Events:  <none>


kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
web-deploy-566bd8fc84-4pncz   1/1     Running   0          7m26s
web-deploy-566bd8fc84-8zln2   1/1     Running   0          7m26s
web-deploy-566bd8fc84-967r8   1/1     Running   0          7m26s
web-deploy-566bd8fc84-cqz82   1/1     Running   0          7m26s
web-deploy-566bd8fc84-zvxzl   1/1     Running   0          7m26s

kubectl delete pod web-deploy-566bd8fc84-4pncz
pod "web-deploy-566bd8fc84-4pncz" deleted

kubectl get pods
NAME                          READY   STATUS              RESTARTS   AGE
web-deploy-566bd8fc84-85l2j   0/1     ContainerCreating   0          5s
web-deploy-566bd8fc84-8zln2   1/1     Running             0          7m41s
web-deploy-566bd8fc84-967r8   1/1     Running             0          7m41s
web-deploy-566bd8fc84-cqz82   1/1     Running             0          7m41s
web-deploy-566bd8fc84-zvxzl   1/1     Running             0          7m41s


Kubectl rollout status deploy web-deploy


Happy Learning😀


Comments

Popular posts from this blog

Kubernetes ETCDCTL

ETCD is a key-value data store for storing kubernetes state and objects. ETCDCTL is the tool used to back up with snapshot. ETCDCTL a command line tool for interacting with the etcd server  Key Features:  Keep the event history until compaction. access to old version of keys. user controlled key compaction. Support range query. pagination support with limit argument. support consistency guarantee across multiple queries. Replace TTL key with lease. Support watch feature. ETCDTOOL Installation: Build binary from source code  Download tool directly  Build binary from source code: Checkout the code repository git clone -b v3.4.16 https://github.com/etcd-io/etcd.git Change directory to etcd cd etcd Run build script ./build The binaries are under the bin directory. exportPATH="$PATH:`pwd`/bin" Check etcd version etcd --version Download ETCD tool directly: kubectl exec -it etcd-docker-desktop -n kube-system -- /bin/bash -c 'ETCDCTL_API=3 /usr/local/bin/etcd --version' | h

Selenium Basic Commands.

Selenium Commands, Packages and Exceptions. Here I have selected few most frequently asked commands in the interview. Recommended way of Importing webdriver from selenium package. from selenium import webdriver. Once webdriver is imported then you are able to access the classes like this webdriver.Firefox webdriver.FirefoxProfile webdriver.Chrome webdriver.ChromeOptions webdriver.Ie webdriver.Opera webdriver.PhantomJS webdriver.Remote webdriver.DesiredCapabilities webdriver.ActionChains webdriver.TouchActions webdriver.Proxy To launch the application URL: driver = webdriver.Chrome driver.get('http://youtube.com') To get URL of the currently loaded page: driver.current_url To close the current window: driver.close() Exceptions in Selenium: Base Exception class: Selenium.common.exceptions selenium.common.exceptions.WebDriverException selenium.common.exceptions.InvalidElementStateException selenium.common.exceptions

Selenium - Architecture

Selenium Architecture: Here, we will learn about the overall selenium architecture. How communication happens from client library to browser and which are all the components involved between them. Architecture compromises of major four components namely Selenium Language Binding JSON Wire Protocol Browser Drivers Real Browsers 1. Selenium Language Binding: Various programming languages provide their own Rest API support for communicating to their respective browser drivers via JSON Wire protocol. python provides 'selenium ' as a client library which has all the rest API i mplementation  for communicating with browser drivers. Selenium is a third party library which does not come in python basic installation.  You need to install it via PIP command : pip install selenium driver = selenium.webdriver.Chrome('location of the chrome driver executable')  Above line returns one chrome browser session , where rest all browser relate