Skip to content

Instantly share code, notes, and snippets.

@andresrinivasan
Last active March 26, 2023 21:58
Show Gist options
  • Select an option

  • Save andresrinivasan/64bf3740d07083ec6456b58f06fc7a48 to your computer and use it in GitHub Desktop.

Select an option

Save andresrinivasan/64bf3740d07083ec6456b58f06fc7a48 to your computer and use it in GitHub Desktop.
Kubernetes

Kubernetes Cheetsheet

Shell in to a pod

kubectl exec -it demo-pod -- /bin/bash

Create a new pod on a specific node

kubectl run test-shell -it --rm --image=ubuntu:18.04 --overrides='{"spec": { "nodeSelector": {"kubernetes.io/hostname": "eks-prod-4"}}}'
  • Use Netshoot --image=nicolaka/netshoot
  • To detach from the shell and leave it running with the ability to re-attach, omit the --rm. Then reattach with kubectl attach $pod-name -c $pod-container -it

Port forward to pod

kubectl port-forward OBJECT local:remote

where OBJECT can be pod, deployment, replicaset, service

Dump current Kube Config to create a standalone config

kubectl config view --minify --flatten

where --minify limits to the current config --flatten include everything so the config is self contained

apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-bank
labels:
app: redis-bank
spec:
replicas: 3
selector:
matchLabels:
app: redis-bank
template:
metadata:
labels:
app: redis-bank
spec:
containers:
- name: redis-bank
image: gcr.io/central-beach-194106/andre/redis-bank:latest
ports:
- containerPort: 8080
env:
- name: SPRING_REDIS_HOST
valueFrom:
secretKeyRef:
name: redb-redb-demo
key: service_name
- name: SPRING_REDIS_PORT
valueFrom:
secretKeyRef:
name: redb-redb-demo
key: port
- name: SPRING_REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redb-redb-demo
key: password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment