Sometimes you just need a container that keeps shell running in a kubernetes cluster. It's very handy to debug or to open an ssh tunnel into the container network.
Unfortunately, the ubtuntu
or busybox
contianers from Docker Hub exit, but this little trick starts the container with a never-ending, ye low CPU consumption tail -f
.
Now you can kubectl exec -it
into the container, which always maintains context.
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: proxytest-deployment
spec:
selector:
matchLabels:
app: proxytest
replicas: 1 # tells deployment to run 2 pods matching the template
template: # create pods using pod definition in this template
metadata:
# unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is
# generated from the deployment name
labels:
app: proxytest
spec:
containers:
- name: service
image: ubuntu:xenial
command: [ "/bin/sh" , "-c", "tail -f /dev/null" ]