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
Post a Comment