K8s Container + VSCode

K8s Container + VSCode

I am huge proponent of remote development, and having resources like K8s Clusters and Home Labs can help improve your Developer Experience by a huge margin. To assist with that goal, I thought that it would be a nice (but a also a bad security issue) to create a local dev container with root permission, running ubuntu and having persistence, to do some quick testing and development. This is specially true if you're working with multiple services which also are specific about the local DNS being used like Redis Cluster for Service Discovery.

First deploy the code below to create a base container with persistence. A service or ingress can be added as required.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dev-deployment
  namespace: default
  labels:
    app: dev
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dev
  template:
    metadata:
      labels:
        app: dev
    spec:
      containers:
      - name: dev-container
        image: ubuntu
        command: ["sleep", "infinity"]
        volumeMounts:
        - mountPath: /root/
          name: dev-volume
      volumes:
      - name: dev-volume
        persistentVolumeClaim:
          claimName: dev-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dev-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Then use the option below to Attach VSCode to the container. 

And voila!