DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Kubectl commands - Kubernetes
Kubectl is a command line interface for running commands against Kubernetes clusters. This overview covers
kubectl
syntax, describes the command operations, and provides common examples. For details about each command, including all the supported flags and subcommands, see the kubectl reference documentation.List all services
kubectl get services
kubectl get svc
List everything
kubectl get all --all-namespaces
Describe service <name>
kubectl describe svc <name>
Get services sorted by name
kubectl get services –sort-by=.metadata.name
List all pods
kubectl get pods
Watch nodes continuously
kubectl get pods -w
Get version information
kubectl get version
Get cluster information
kubectl get cluster-info
Get the configuration
kubectl config view
Output information about a node
kubectl describe node <node-name>
List the replication controllers
kubectl get rc
List the replication controllers in specific <namespace>
kubectl get rc -n <namespace-name>
Describe replication controller <name>
kubectl describe rc <name>
Delete pod <name>
kubectl delete pod <name>
Delete replication controller <name>
kubectl delete rc <name>
Delete service <name>
kubectl delete svc <name>
Remove <node> from the cluster
kubectl delete node <name>
Show metrics for nodes
kubectl top nodes
Show metrics for pods
kubectl top pods
Watch the Kublet logs
watch -n 2 cat /var/log/kublet.log
Get logs from service <name>, optionally selecting container <$container>
kubectl logs -f <name> [-c <$container>]
execute <command> on <service>, optionally selecting container <$container>
kubectl exec <service> <command> [-c <$container>]
Initialize your master node
kubeadm init
Join a node to your Kubernetes cluster
kubeadm join --token <token> <master-ip>:<master-port>
Create namespace <name>
kubectl create namespace <namespace>
Allow Kubernetes master nodes to run pods
kubectl taint nodes --all node-role.kubernetes.io/master
Reset current state
kubeadm reset
List all secrets
kubectl get secrets
Launch a pod called <name> ,using image <image-name>
kubectl run <name> --image=<image-name>
Create a service described in <manifest.yaml> file
kubectl create -f <manifest.yaml>
Validate yaml file with dry run
kubectl create --dry-run --validate -f sysaix.yaml
Scale replication controller
kubectl scale rc <name> --replicas=<count>
Stop all pods on specific pods
kubectl drain <n> --delete-local-data --force --ignore-deamonsets
Explain resource
kubectl explain pods
kubectl explain svc
Open a bash terminal in a pod
kubectl exec -it sysa'xpod sh
Check pod environment variables
kubectl exec sysaixpod env
Filter pods by label
kubectl get pods -l owner=emre
List statefulset
kubectl get sts
Scale statefulset
kubectl scale sts <stateful_set_name> --replicas=5
Delete statefulset only (not pods)
kubectl delete sts <stateful_set_name> --cascade=false
View all events
kubectl get events --all-namespaces