Kubernetes Cheatsheet: Kubectl
Kubernetes Cheatsheet: Kubectl
kubectl
kubectl get all
kubectl get pods
kubectl get pods -w // Watch for changes
kubectl get pods -A // All namespaces
kubectl get pods -o wide // Wide output
kubectl get services -n kube-system // Only for specific namespace
kubectl get replicasets
kubectl get deployments
kubectl delete deployments --all
kubectl get pv
kubectl get pvc
kubectl get nodes
kubectl get secrets
kubectl get hpa
kubectl describe secrets/mysecret
kubectl get secret mysecret -o yaml // Output this secret in yaml
kubectl top pods // View the resource consumption for pods
(requires metrics-server)
kubectl top nodes // View the aggregated resource
consumption for nodes (requires metrics-server)
kubectl autoscale deployment api-gateway --cpu-percent 400 --min 1 --max 5 // HPA or
Horizontal Pod Autoscaler (cpu-percent is relevant to requested)
kubectl get hpa api-gateway -o yaml // Output this hpa in yaml so that you can save and reuse
kubectl get roles
kubectl get rolebindings
kubectl create ns playground
kubectl config view // View kubeconfig settings
kubectl get configmaps
kubectl get ingress
minikube
minikube start --cpus 4 --memory 8Gi
minikube stop
minikube delete
minikube ip
minikube addons
minikube addons list // Get the list of minikube add-ons
minikube addons enable metrics-server // Enable metrics-server for kubectl metrics via
‘top’ command
minikube addons enable dashboard // Enable GUI dashboard
minikube dashboard // Run dashboard easily
kops
brew install awscli // Install aws cli tool
brew install kops // Install k8s operations tool
aws configure // Use your new access and secret key here
aws iam list-users // You should see a list of all your IAM users here
// Because "aws configure" doesn't export these vars for kops to use, we export them now
export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)
helm
brew install helm
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo update
helm install monitoring stable/prometheus-operator
kubectl service/monitoring-prometheus-oper-prometheus // change type to LoadBalancer