{ Josh Rendek }

<3 Go & Kubernetes

Kubernetes

Snippets

Upgrade kube state metrics

1
helm upgrade  ksm prometheus-community/kube-state-metrics

Create a temp pod on a specific host with tolerations

1
2
3
4
5
6
kubectl run -i --rm --tty busy7 --image=alpine:latest --overrides='{"spec": { "nodeSelector": {"kubernetes.io/hostname": "HOSTNAME"}, "tolerations": [{
      "key": "TAINT_NAME",
      "operator": "Equal",
      "value": "true",
      "effect": "NoSchedule"
    }]}}' -- sh

Create temp pod

1
kubectl run -i --rm --tty temp --image=alpine:latest -- sh

Copy a secret between namespaces

1
kubectl get secret secret-name --namespace=from-ns -o yaml | sed 's/namespace: from-ns/namespace: to-ns/g' | kubectl apply --namespace=to-ns -f -

List all ingresses

1
kubectl get ing -o json | jq -r '.items[].spec.rules[].http.paths[]'

Get taints on nodes

1
kubectl get nodes -o json | jq '.items[].spec.taints'

Run cron job one off

1
kubectl create job --from=cronjob/<name of cronjob> <name of job>

Port-forward a service

1
kubectl port-forward svc/name-of-svc local_port:pod_port

Copy from remote container to local

1
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

Add registry credentials to a namespace

1
2
3
4
5
6
export REGISTRY_USERNAME="username"
export REGISTRY_PASSWORD="password"
export NAMESPACE="default"
kubectl create secret -n $NAMESPACE docker-registry --docker-server=registry.yourdomain.com --docker-username=$REGISTRY_USERNAME \
    --docker-password="$REGISTRY_PASSWORD" container-registry
kubectl patch sa default -n $NAMESPACE -p '"imagePullSecrets": [{"name": "container-registry" }]'

EKSCTL add role to admin

1
eksctl create iamidentitymapping help --name staging --role arn:aws:iam::account_number:role/kube-admin --group system:masters --username admin