title: How to get SSH running on Kubernetes?
body: <p>I'm trying to get sshd running in my Kubernetes cluster so that I can set up a reverse proxy/ngrok tunnel per <a href="https://jerrington.me/posts/2019-01-29-self-hosted-ngrok.html" rel="nofollow noreferrer">this blog post</a>.</p>
  <p>I've got nginx running, but I can't seem to connect to SSH.</p>
  <p>Here's the complete Kubernetes config:</p>
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    name: dev-example-ingress
    namespace: dev-example
    annotations:
      kubernetes.io/ingress.class: nginx
      cert-manager.io/cluster-issuer: letsencrypt-prod
  spec:
    tls:
      - hosts:
          - dev.example.ca
        secretName: dev-example-tls
    rules:
      - host: dev.example.ca
        http:
          paths:
            - backend:
                serviceName: app-service
                servicePort: 80
            - backend:
                serviceName: app-service
                servicePort: 2222
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: app-service
    namespace: dev-example
  spec:
    selector:
      pod: my-pod-label
    ports:
      - name: http
        protocol: TCP
        port: 80
      - name: ssh-tcp
        protocol: TCP
        port: 2222
  #    - name: ssh-udp
  #      protocol: UDP
  #      port: 2222
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: app-deployment
    namespace: dev-example
  spec:
    revisionHistoryLimit: 3
    selector:
      matchLabels:
        pod: my-pod-label
    template:
      metadata:
        labels:
          pod: my-pod-label
      spec:
        imagePullSecrets:
          - name: regcred
        containers:
          - name: nginx
            image: dreg.example.ca/example/dev.example.ca
            ports:
              - name: http
                containerPort: 80
          - name: sshd
            image: linuxserver/openssh-server
            ports:
              - name: ssh
                containerPort: 2222
            env:
              - name: PUID
                value: '1000'
              - name: PGID
                value: '1000'
              - name: TZ
                value: America/Los_Angeles
              - name: USER_NAME
                value: example
              - name: USER_PASSWORD
                value: test
  </code></pre>
  <p>But when I try to connect it says &quot;connection refused&quot;:</p>
  <pre><code>❯ ssh -p 2222 example@dev.example.ca
  ssh: connect to host dev.example.ca port 2222: Connection refused
  </code></pre>
  <p>I don't know if that means I didn't expose the port properly or what.</p>
  <p>I'm pretty sure <a href="https://registry.hub.docker.com/r/linuxserver/openssh-server" rel="nofollow noreferrer"><code>linuxserver/openssh-server</code></a> is running on port 2222. If I run <code>ps -aux</code> in that container I get:</p>
  <pre><code>^@root@app-deployment-5d9567dcc5-f5hq6:/# ps -aux
  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  root         1  0.0  0.0    200     4 ?        Ss   19:26   0:00 s6-svscan -t0 /var/run/s6/services
  root        34  0.0  0.0    200     4 ?        S    19:26   0:00 s6-supervise s6-fdholderd
  root       277  0.0  0.0    200     4 ?        S    19:26   0:00 s6-supervise openssh-server/log
  root       278  0.0  0.0    200     4 ?        S    19:26   0:00 s6-supervise openssh-server
  mpen       280  0.0  0.0    256     4 ?        Ss   19:26   0:00 s6-log n30 s10000000 S30000000 T !gzip -nq9 /config/logs/openssh
  mpen       281  0.0  0.0   4384  3480 ?        Ss   19:26   0:00 sshd: /usr/sbin/sshd -D -e -p 2222 [listener] 0 of 10-100 startups
  root       298  0.5  0.0   2580  2304 pts/0    Ss   19:32   0:00 bash
  root       307  0.0  0.0   1640   868 pts/0    R+   19:32   0:00 ps -aux
  </code></pre>
  <p>What am I missing?</p>
  <p>I'm open to using other ssh docker images if they work better/are easier. This is just for dev.</p>