Kubectl Commands

Information Commands

CommandDescription

kubectl cluster-info

Display Cluster Info
kubectl config viewDisplay Config


kubectl get pods

List all running pods
kubectl get servicesList all services
kubectl get nodesList all nodes

kubectl get deployments

Deployments view
kubectl get rcList replication controllers

kubectl get pods -o wide

List all pods in ps output format with more information (such as node name).

kubectl get pods --all-namespaces

List all pods in all namespaces


kubectl logs <pod>

Display the logs for a service
kubectl logs -f <pod>Display the logs for a service

kubectl logs -n kube-system <system_pod>

Display logs for a system pod

kubectl exec -ti <POD-ID-HERE> bash -n kube-system

Log into a system pod


kubectl delete pod <POD> --grace-period=0 --forceForce delete a pod


kubectl get pspGet Pod Security Policies
kubectl edit deployment <deployment>Edit an object directly.


Actions

CommandDescription

kubectl port-forward service/<SERVICE> <LOCAL_PORT>:<SERVICE_PORT>


Port Forward / Proxy to a Service

See: kubectl port-forward --help


kubectl port-forward service/kafka-cp-kafka 9092:9092

kubectl proxy --address 0.0.0.0 --accept-hosts '.*'
Allow proxying from any host listening on all interfaces
kubectl create -f <yaml file>Create a deployment
kubectl delete -f <yaml file>Delete a deployment
kubectl apply -f <yaml file>Update a deployment
kubectl edit -f <yaml file>Edit and update a deployment
kubectl edit deployment <deployment>Edit an object directly.


kubectl exec -it <pod> bash

log into a pod



kubectl scale --replicas=3 deployment/<deployment>

Scale the number of pods for a deployment

$ kubectl scale --replicas=3 deployment/cloudservice

kubectl scale --replicas=1 -f <yaml file>Scale the number of pods referenced in a yaml file


kubectl delete deployment <deployment>

Delete all pods for a deployment

kubectl delete pod <pod instance>

Delete a pod

kubectl delete pvc --all

Delete all pvc


kubectl expose deployment cloudservice --type=LoadBalancer --name=cloud

Expose deployment


kubectl patch deployment notification-controller --patch "$(cat patch.yaml)"Apply a patch 


kubectl rollout restart deployment/myapp Redeploy all pods for a deployment. Helpful after making a configmap change.


PVC stuck in status “Terminating” Fix

kubectl patch pvc {PVC_NAME} -p '{"metadata":{"finalizers":null}}'

Can also be applied to pv.




Minikube Commands

CommandDescription
minikube startStart
minikube stopStop
minikube dashboardDisplay dashboard
minikube sshlog into minikube

ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip)

log into minikube
cat ~/.minikube/machines/minikube/config.jsonView minikube config


ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip) -R 5000:localhost:5000

SSH into minikube and setup a port forwarding to your local docker registry.
minikube ipget ip of minikube
minikube service <service>Open browser to exposed service


Reference

  • No labels