Kubernetes cheat sheet
Kubernetes Cluster commands
Cluster Information
kubectl cluster-info
API Versions supported in Kubernetes
kubectl api-versions
API Resources available in Kubernetes
kubectl api-resources
Kubernetes get Object Info
List all kubernetes objects in the namespace
kubectl get all -n <namespace>
List all pods
kubectl get pods -n <namespace>
List Network policy
I:\k8s-deploy>kubectl get netpol -n <namespace>
NAME POD-SELECTOR AGE
allow-ingress-to-helloworld-policy app=helloworld 22h
Output Formats
Kubernetes supports multiple output format such as : yaml, json, wide, name, . You can use -o flag
kubernetes Deployment Commands
Apply yml definition to kubernetes
kubectl apply -f <file_name.yml> -f <namespace>
Running a Docker image in Interactive mode in kubernetes cluster
kubectl run --generator=run-pod/v1 --image hr4g67xo8d45/product-service -it product-service -- /bin/bash
Delete any kubernetes object
kubectl delete -n <namespace> <object_type>/<object_name> ...
for example :
kubectl delete -n <namespace> pod/nginx-wdswe2-343dcd service/nginx
Delete all kubernetes objects defined in an yaml file
kubectl delete -f <file_name.yml> -f <namespace>