The Ops Community ⚙️

Joseph D. Marhee
Joseph D. Marhee

Posted on

Deploying Coder on Kubernetes

Coder provides "self-hosted
developer workspaces" which includes things like the code-server for web-based VSCode instances for your development teams.

Deploying the Coder suite for this demonstration to Kubernetes just relies on a single Pod (this can easily be made into a Deployment or some other replication controller, if you have reliable distributed storage to back the coder-volume data) to configure before we expose the service:

apiVersion: v1
kind: Pod
metadata:
  name: coder
  namespace: coder
  labels:
    app: coder
spec:
  containers:
  - name: coder
    image: codercom/coder:1.29.0
    securityContext:
      privileged: true
      runAsUser: 0
    ports:
    - name: coder-http
      containerPort: 7080
    volumeMounts:
    - mountPath: /data
      name: coder-volume
    - mountPath: /var/run/docker.sock
      name: docker-socket
  volumes:
  - name: coder-volume
    hostPath:
      path: /opt/coder-data
      type: Directory
  - name: docker-socket
    hostPath:
      path: /var/run/docker.sock
      type: Socket
Enter fullscreen mode Exit fullscreen mode

Keep in mind there are a few things gojng on here: You need to mount the host system's Docker socket file (so it can launch other container workloads), and also needs a data volume so you cna persist data. I used a hostPath volume here for demonstration purposes, but I recommend a PersistentVolume for any kind of production use.

To expose the UI, I typically create a Service and then Ingress (rather than through a LoadBalancer-type Service alone):

---
apiVersion: v1
kind: Service
metadata:
  name: coder-service
  namespace: coder
spec:
  selector:
    app: coder
  ports:
    - protocol: TCP
      port: 80
      targetPort: 7080
      name: "http-app"
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: coder-ingress
  namespace: coder
spec:
  rules:
    - host: "coder.kube.c00lz0ne.internal"
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name:  coder-service
                port:
                  number: 80
Enter fullscreen mode Exit fullscreen mode

From here, head to your above hostname, and you can access the Coder UI to complete your environment's administrative setup.

Top comments (0)