apiVersion: apps/v1
kind: Deployment
metadata:
  name: code-server
  namespace: apps
  labels:
    app: code-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: code-server
  template:
    metadata:
      labels:
        app: code-server
        name: code-server
    spec:
      containers:
        - name: code-server
          image: bencdr/code-server-deploy-container
          imagePullPolicy: IfNotPresent
          securityContext:
            runAsUser: 1000
          ports:
            - containerPort: 8080
              name: web
              protocol: TCP
          env:
            - name: START_DIR
              value: "/home/coder/code"
          volumeMounts:
            - name: data
              mountPath: "/home/coder"
          livenessProbe:
            initialDelaySeconds: 10
            periodSeconds: 5
            failureThreshold: 4
            exec:
              command:
              - sh
              - -c
              - curl -s http://localhost:8080
          readinessProbe:
            initialDelaySeconds: 10
            periodSeconds: 5
            failureThreshold: 4
            exec:
              command:
              - sh
              - -c
              - curl -s http://localhost:8080
          resources:
            requests:
              cpu: 200m
              memory: 256Mi
            limits:
              cpu: 3000m
              memory: 2560Mi
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: nfs-code-server

---

apiVersion: v1
kind: Service
metadata:
  name: code-server
  namespace: apps
  labels:
    name: code-server
spec:
  type: ClusterIP
  selector:
    app: code-server
  ports:
    - name: code-server
      targetPort: web
      port: 80
      protocol: TCP

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: apps
  name: code-server-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://id.junv.me/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://id.junv.me/oauth2/start?rd=https%3A%2F%2F$host$request_uri"
spec:
  tls:
  - hosts:
    - code.junv.me
    secretName: code-server-tls
  rules:
  - host: code.junv.me
    http:
      paths:
      - backend:
          service:
            name: code-server
            port:
              number: 80
        path: /
        pathType: Prefix
