Skip to content

Instantly share code, notes, and snippets.

@xtophs
Last active July 10, 2023 11:48
Show Gist options
  • Save xtophs/cf6f5d56ec6d3eb3e08d057826b58af6 to your computer and use it in GitHub Desktop.
Save xtophs/cf6f5d56ec6d3eb3e08d057826b58af6 to your computer and use it in GitHub Desktop.
Keep Ubuntu running in Kubernetes

Keep an Ubuntu container running in a Kubernetes cluster

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" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment