Friday, June 2, 2023

Kubernetes Commands

kubectl get nodes returns available nodes in k8s cluster

kubectl get po returns available pods in k8s cluster

kubectl get po -o wide return ip address and other details of pod 

kubectl create -f poddemo.yml create pod using yml file. this will create a pod with nginx

Sample yaml file for pod creation 

apiVersion: v1
kind: Pod
metadata:
    name: nginx-pod
    labels:
        app: nginx
        tier: dev
spec:
    containers:
        - name: nginx-container
          image: nginx

kubectl describe pod nginx-pod returns details about pod

kubectl delete pod nginx-pod delete pod nginx-pod

kubectl delete pod --all delete all pods

kubectl expose pod nginx-pod --type="NodePort" --port=8080 expose pod in 8080 port as a service

kubectl get svc returns services exposed

kubectl delete svc nginx-pod delete service  nginx-pod

kubectl exec -it nginx-caching-server bash access to nginx-caching-server bash terminal

kubectl exec -it nginx-caching-server -c busybox-container2 sh access nginx-caching-server pod's container "busybox-container2" for sh

kubectl get rc returns returns replica controllers

kubectl get rs returns replica set

kubectl scale rc nginx-rc --replicas=5 scale replica controller size to 5 for nginx-rc

kubectl delete  rc --all delete all replica controllers

kubectl delete  rs --all delete all replica sets

kubectl label nodes node2 diskType=ssd change node 2's diskType to ssh

kubectl get nodes --show-labels returns all labels

kubectl get job return batch job details

kubectl describe jobs countdown retrieve details about countdown pod's job

kubectl logs countdown-rmc97 returns logs of "countdown-rmc97" container

kubectl get deploy returns deployments

kubectl delete deploy --all delete all deployments 

kubectl describe deploy nginx-deploy returns details of "nginx-deploy" deployment

kubectl set image deploy nginx-deploy nginx-container=nginx:1.9.1 --record change the image of nginx to 1.9.1

kubectl rollout status deployment/nginx-deploy returns rollout status of nginx-deploy

kubectl rollout history deployment/nginx-deploy returns rollout history of nginx-deploy

kubectl rollout undo deployment/nginx-deploy undo the changes 

kubectl rollout status deployment/nginx-deploy returns rollout status of nginx-deploy

kubectl describe deploy nginx-deploy | grep -i image returns image details of nginx-deploy

kubectl edit deployment redis-deployment edit the deployment configurations of "redis-deployment"

No comments:

Post a Comment