Skip to content

Instantly share code, notes, and snippets.

@yesnik
Last active November 1, 2024 18:09
Show Gist options
  • Save yesnik/a21a478e94129c5b96b202a49022a0a2 to your computer and use it in GitHub Desktop.
Save yesnik/a21a478e94129c5b96b202a49022a0a2 to your computer and use it in GitHub Desktop.
Kubernetes Commands

Kubernetes Commands

Kubectl

It is a kubernetes command line tool. It controls the Kubernetes cluster manager. It allows to run commands against our cluster.

  • kubectl version - show the client and server version info
  • kubectl api-resources - show all Kubernetes resources
  • kubectl run hello-nginx --image=nginx:latest --port=80 - start a nginx pod, let the container expose port 80
  • kubectl get pod hello-nginx -o wide - show one-liner info about the pod
  • kubectl describe pod hello-nginx - show info about the pod
  • kubectl describe deployment hello-nginx - show info about deployment 'hello-nginx'
  • kubectl exec -it hello-nginx -- sh - SSH into the container (if 1 container in the pod)
  • kubectl exec -it hello-nginx -c hello-kenny -- sh - SSH into the container 'hello-kenny' (if many containers in the pod)
  • kubectl exec hello-nginx -- ls /var - execute command in the container
  • kubectl get events --sort-by=.metadata.creationTimestamp - show logs to find a reason of problem with ContainerCreating Status
  • kubectl get namespaces - show all namespaces
  • kubectl get nodes - show nodes in the cluster
  • kubectl get pods - show running pods
  • kubectl get pod -n kube-system - show pods in the namespace
  • kubectl get pods -A - show all pods in all namespaces
  • kubectl get all -A - show everything in all namespases
  • kubectl get deployments - show deployments
  • kubectl delete deployment hello-nginx - delete deployment 'hello-nginx'
  • kubectl get replicaset, kubectl get rs - show replicasets
  • kubectl logs hello-nginx - show logs of the default container
  • kubectl logs hello-nginx -c hello-kenny - show logs of the container 'hello-kenny' within the pod 'hello-nginx'
  • kubectl port-forward pod/hello-nginx 8080:80 - forward port 8080 from host to port 80 in the container
  • kubectl delete pod hello-nginx - delete pod
  • kubectl apply -f hello-nginx.yml - create pod from .yml file
  • kubectl replace --force -f deployment.yml - apply changes from .yml file in forced mode
  • kubectl delete -f hello-nginx.yml - delete pod
  • kubectl rollout history deployment - show deployments history
  • kubectl rollout history deployment hello-nginx --revision=2 - show info about specific deployment revision
  • kubectl rollout undo deployment hello-nginx - rollback deployment hello-nginx
  • kubectl rollout status deployment hello-nginx - show info about rollout status

Minikube

  • minikube config set driver docker - set docker as default driver
  • minikube start - start a local Kubernetes cluster
  • minikube start --alsologtostderr --v=2 - start minikube and output all the important debug logs to stderr
  • minikube start --vm-driver hyperv - start minikube using HyperV instead default VirtualBox driver
  • minikube start --nodes=2 - start cluster with 2 nodes
  • minikube dashboard - access the Kubernetes dashboard running within the minikube cluster
  • minikube node add - add node to an existing cluster
  • minikube node delete m02 - delete node with name m02 from cluster
  • minikube stop - stop a running local Kubernetes cluster
  • minikube delete - delete a local Kubernetes cluster
  • minikube delete --all - delete all local clusters and profiles
  • minikube status - show the status of a local Kubernetes cluster
  • minikube ssh - SSH into the node
  • minikube ip - shows the IP of master node
  • minikube ip --node=minikube-m02 - show the IP of node
  • minikube node list - lists nodes
  • minikube logs --node minikube-m02 -f - show logs of the node, -f - following
  • minikube image build -t local/customer:1 . - build image with minikube
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment