Skip to content

Instantly share code, notes, and snippets.

@koobitor
Last active January 3, 2018 07:32
Show Gist options
  • Save koobitor/20cf42268952bcaaacbc2a32068fec49 to your computer and use it in GitHub Desktop.
Save koobitor/20cf42268952bcaaacbc2a32068fec49 to your computer and use it in GitHub Desktop.

Check Version

kubectl version

Get Docs Help

kubectl <cmd> --help

Cluster details

kubectl cluster-info

Shows all nodes

kubectl get nodes

Creates a new deployment

kubectl run
kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080
kubectl run hello-server --image=gcr.io/google-samples/hello-app:1.0 --port 8080

List your deployments

kubectl get deployments

Delete deployments

kubectl delete deployments [deploy-name]

Expose your application

kubectl expose deployment [deploy-name] --type="LoadBalancer"

Service Inspect

kubectl get service [deploy-name]

Service Delete

kubectl delete service [deploy-name]

Create a route using a proxy

kubectl proxy

Get the name of the Pod

export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
echo Name of the Pod: $POD_NAME
curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME/

Get list pods

kubectl get pods

Get details about the Pod’s container

kubectl describe pods

Get logs from the container

kubectl logs $POD_NAME

Execute commands directly on the container

kubectl exec $POD_NAME env

Start a bash session

kubectl exec -ti $POD_NAME bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment