Skip to content

Instantly share code, notes, and snippets.

@aabs
Last active November 20, 2017 21:23
Show Gist options
  • Save aabs/00def7b3097049d287055554f6456c30 to your computer and use it in GitHub Desktop.
Save aabs/00def7b3097049d287055554f6456c30 to your computer and use it in GitHub Desktop.
neat ways to use k8s on the command line

Useful tips and tricks

Run busybox

kubectl run -i --tty busybox --image=busybox --restart=Never -- sh

get pods using a label selector

 kubectl get --namespace kafka pods --selector="app=zookeeper"

Expose akubectl run -i --tty busybox --image=busybox --restart=Never -- sh pod as a load balanced service

$ kubectl run myapp-prod \
image=gcr.io/kuar-demo/kuard-amd64:1 \
replicas=3 \
port=8080 \
labels="ver=1,app=myapp,env=prod" 

$ kubectl expose deployment myapp-prod

access internal ports

MY_POD=$(kubectl get pods l app=myapp \ o jsonpath='{.items[0].metadata.name}') 
kubectl port-forward $MY_POD 48858:8080

Create kubernetes secret

Obtain a slack token from this page and then deploy a secret to kubernetes with this command:

$ kubectl create secret generic somename --from-literal=key=VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment