Skip to content

Instantly share code, notes, and snippets.

@macghriogair
Created March 24, 2019 20:27
Show Gist options
  • Save macghriogair/6b0c88d5a3634a39c8531ef95e418c42 to your computer and use it in GitHub Desktop.
Save macghriogair/6b0c88d5a3634a39c8531ef95e418c42 to your computer and use it in GitHub Desktop.
[Kubernetes cheatsheet]

Kubernetes

Create Deployment

kubectl run <DEPLOYMENT> -- image= <IMAGE> --port= <PORT>

Get Deployments

kubectl get deployments

Get Pod Name

export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')

Start Proxy

kubectl proxy

make a reqeust to pod via proxy

curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME

Create a (publicly exposed) Service

kubectl get services

kubectl expose deployment <DEPLOYMENT_NAME> -- type="LoadBalancer" --port 8080

kubectl describe services/NAME

Get Node Port

export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')
echo NODE_PORT=$NODE_PORT

Get labelled Pods / Services

kubectl get pods -l run=MY_NAME

kubectl get services -l run=MY_NAME

Apply a label

kubectl label pod $POD_NAME app=v1
kubectl get pods -l app=v1

Delete a Service

kubectl delete service -l run=MY_NAME

Scale Pods

kubectl scale deployments/kubernetes-bootcamp --replicas=4

Rolling Updates

View current version

kubectl describe pods

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

Verify status

kubectl rollout status deployments/kubernetes-bootcamp

Rollback

kubectl rollout undo deployments/kubernetes-bootcamp

TUTRORIALs

https://de.udacity.com/course/scalable-microservices-with-kubernetes--ud615

Create Pods from Yaml

kubectl create -f pod-nginx.yml

Check if running with Busybox

kubectl get pods 

kubectl run busybox --image=busybox --restart=Never --tty -i --generator=run-pod/v1 --env "POD_IP=$(kubectl get pod nginx -o go-template='{{.status.podIP}}')"

u@busybox$ wget -qO- http://$POD_IP # Run in the busybox container
u@busybox$ exit # Exit the busybox container
$ kubectl delete pod busybox # Clean up the pod we created with "kubectl run"

Bash on a Pod

kubectl exec -it <PODNAME> -- /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment