Skip to content

Latest commit

 

History

History
207 lines (129 loc) · 3.08 KB

File metadata and controls

207 lines (129 loc) · 3.08 KB

Frequent command use with K8s

Get Cluster info

kubectl cluster-info

Get pods

 kubectl get pods -n defaul

kubectl get pods -n namespacename

Get nodes

kubectl get nodes

Describe pods

kubectl describe pods podname

Create a pod with and wiothout pod yml

 kubectl run nginx --image nginx

kubectl create -f pod.yml

Create a replicaset

kubectl create -f replicaset-definition.yml

Check a replicaset

kubectl get replicaset

Delete a replicaset

kubectl delete replicaset nginx-replicaset

Scale a replicaset

kubectl replace -f replicaset-definition.yml
kubectl scale --replicas=6 -f replicaset-definition.yml

Create a deployment

kubectl create -f deployment-definition.yml

Check a deployment

kubectl get deployments

Delete a deployment

kubectl delete deployment nginx-deployment

Name Space

kubectl create namespace dev

kubectl create -f namespace-definition.yml

Check a namespace

kubectl get namespaces

Check pods in all namespace

kubectl get pods -all

Check the Service

kubectl get services

Create the Service

kubectl create -f service-definition.yml

Good to know the commands

 Create an Nginx Pod

  kubectl run nginx --image=nginx

Generate POD manifest YAML file (-o yaml). DRY run

 kubectl run nginx --image= nginx --dry-run=client -o yaml

Create Deployment

kubectl create deployment --image=nginx nginx

Generate Deployment YAML file. DRY run

kubectl create deployment --image=nginx nginx --dry-run=client -o yaml

Create a Service

kubectl expose pod redis --port=6379 --name=redis --dry-run=client -o yaml

kubectl create service clusterip redis --tcp=6379:6379 --dry-run=client -o yaml

kubectl expose pod nginx --port=80 --name nginx --type=Nodeport --dry-run=client -o yaml

kubectl create service nodeport nginx --tcp=80:80 --node-port=30080 --dry-run=client -o yaml

Taint a Node

kubectl taint nodes node01 spray=mortein:NoSchedule

Untaint a Node

kubectl taint nodes master node-role.kubernetes.io/master:NoSchedule-

Node Selectors

kubectl label node node-name key=value

Affinity

DaemonSets

kubectl get daemonsets name

Secrets

kubectl create secret generic app-secret --from-literal=DB_HOST=mysql --from
echo -n "mysql" | base64

to decode

echo -n "mysql base64 decode"
kubectl describe secrets
kubectl get secrets

Maintenance

kubectl drain node-1

# To make node schedulable

kubectl uncordon node-1

# To make mark node unschedulable

kubectl cordon node-1