kubectl
get
# get status of nodes
kubectl get nodes

# get pods
kubectl get pods
kubectl get pod  --watch # continuously monitor pods

# get services
kubectl get services
kubectl get svc

# get deployments
kubectl get deployment
kubectl get deploy
kubectl get deployment [deploymentName] -o yaml # get configuration

# get pods, services, deployments, statefulsets, replicasets
kubectl get all

# get secret
kubectl get secret

# get configMap
kubectl get configmap

# get namespace
kubectl get namespaces
        
create
# create pod and replicaset
# kubectl create deployment [Name] --image=image
# deployment -> replicaset -> pod -> container
kubectl create deployment redis-deploy --image=redis:alpine # by default, pull images from docker.io

# create component from files
# kubectl create -f [fileName]
kubectl create -f k8s/redis-deployment.yaml
# kubectl create -f [directoryName]
kubectl create -f k8s
        
edit
# edit deployment
# create an automatically generated compose file, edit, and save
# termiante the old pod and create a new pod using the editted deployment
kubectl edit deployment redis-deploy
        
logs
kubectl logs [podName]
        
describe
# describe pod
kubectl describe pod [podName]

# describe service
kubectl describe service [serviceName] # get podIP:podPort connected to the service
        
delete
# delete deployment
kubectl delete deployment [deploymentName]
kubectl delete deploy [deploymentName]

# delete service
kubectl delete service [serviceName]
kubectl delete svc [serviceName]

# delete from configuration files
# kubectl delete -f [fileName]
kubectl delete -f k8s/redis-deployment.yaml
#kubectl delete -f [directoryName]
kubectl delete -f k8s
        
exec
# access container
kubectl exec -it [podName] -- sh
        
apply
# create or update components
# kubectl apply -f [fileName]
kubectl apply -f k8s/redis-deployment.yaml

# kubectl apply -f [directoryName]
kubectl apply -f k8s
        
port-forward
# kubectl port-forward svc/[serviceName] [accessPort]:[servicePort]
kubectl port-forward svc/perceptor-service 8080:8082
        
kubectl api-resources --namespaced=true # list namespaced resources
kubectl api-resources --namespaced=false # list non-namespaced resources
        
version
kubectl version
        
config
# get clusters
kubectl config get-clusters

# get current cluster
kubectl config current-context
        
cluster-info
# list clusters
kubectl ctx

# switch cluster
kubectl ctx [clusterName]

# display control plane and CoreDNS
kubectl cluster-info

# get debug and diagnose information
kubectl cluster-info dump
        
Reference
  • Cheat Sheet
  • Documentation
  • Reference