Skip to content

Instantly share code, notes, and snippets.

@skipperkongen
Last active July 18, 2019 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skipperkongen/ea8cd9421fdfb63e1757ac1dc8b3834f to your computer and use it in GitHub Desktop.
Save skipperkongen/ea8cd9421fdfb63e1757ac1dc8b3834f to your computer and use it in GitHub Desktop.
Kubernetes cheat sheet

Kubernetes Cheat Sheet

Example: nginx

Run nginx:

# kubectl run web --image=nginx
kubectl create deployment web --image=nginx

Expose nginx on the internet:

kubectl expose deploy/web --type=NodePort --port=80

Get the nginx web page:

# Get pod ID
POD_ID=$(kubectl get pods -l app=web -o json | jq -r '.items[0].metadata.name')

# Get public IP of pod (works because nginx uses ubuntu)
kubectl exec -it $POD_ID -- apt-get update
kubectl exec -it $POD_ID -- apt-get install -y curl 
PUBLIC_IP=$(kubectl exec -it $POD_ID -- curl ifconfig.me)

# Get nodePort
PUBLIC_PORT=$(kubectl get svc web -o json | jq -r '.spec.ports[0].nodePort')

echo "Public IP and port found... $PUBLIC_IP:$PUBLIC_PORT"

# Get web page
curl $PUBLIC_IP:$PUBLIC_PORT

Example: flaskdemo

Run flaskdemo:

kubectl create deployment flaskdemo --image=skipperkongen/flaskdemo:latest

Expose flaskdemo on the internet:

kubectl expose deploy/flaskdemo --type=NodePort --port=5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment