Skip to content

Instantly share code, notes, and snippets.

@skipperkongen
Last active July 18, 2019 18:23
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