Useful Commands for Kubernetes
From Luis Gallego Hurtado - Not Another IT guy
Cheatsheets
https://linuxacademy.com/site-content/uploads/2019/04/Kubernetes-Cheat-Sheet_07182019.pdf?x87162
General Commands
- Retrieve Kubernetes version
kubectl version
- Retrieve information about Kubernetes cluster
kubectl cluster-info
- Retrieve status of Kubernetes components
kubectl get componentstatuses
- Retrieve all Kubernetes resources in default namespace
kubectl get all
Infrastructure
- Retrieve Kubernetes node (host on which the cluster is deployed)
kubectl get nodes -o wide
Role Based Access Control (RBAC) Authorization
- Retrieve Kubernetes roles at cluster level
kubectl get clusterroles
- Retrieve Kubernetes role bindings at cluster level
kubectl get clusterrolebindings
- Retrieve Kubernetes roles at namespace level
kubectl get roles
- Retrieve Kubernetes role bindings at namespace level of all namespaces
kubectl get rolebindings -all-namespaces
- Retrieve description of a Kubernetes role binding at cluster level
kubectl describe clusterrolebinding cluster-admin
Running Containers
- Retrieve Kubernetes pods
kubectl get pods -o wide
kubectl get pods -n kube-system
- Retrieve Kubernetes replication controllers
kubectl get rc -o wide
- Retrieve Kubernetes deployments
kubectl get deployments -o wide
kubectl get deployments -o wide
- Retrieve Kubernetes services
kubectl get services -o wide
- Run a command into a running pod
kubectl exec –it <pod_name> -- /bin/sh
Manually Login to an external Kubernetes Cluster
https://blog.christianposta.com/kubernetes/logging-into-a-kubernetes-cluster-with-kubectl
kubectl config set-credentials <USER_ENTRY> --username=<USERNAME> --password=<PASSWORD>
kubectl config set-cluster <CLUSTER_NAME> --insecure-skip-tls-verify=true --server=https://<IP_OF_KUBERNETES_API>
kubectl config set-context <CONTEXT_NAME> --user=<USER_ENTRY> --namespace=<NAMESPACE> --cluster=<CLUSTER_NAME>
kubectl config use-context <CONTEXT_NAME>