<p>I'm having trouble setting up keycloak on Kubernetes. I have a load balancer set up (nginx ingress controller) that terminates SSL. I've tried many different configurations but all I'm getting is 502, 503 and 404 errors when I try the /auth endpoint. Here is my deployment.yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: keycloak
  namespace: default
  labels:
    app: keycloak
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak
  template:
    metadata:
      labels:
        app: keycloak
    spec:
      containers:
      - name: keycloak
        image: bitnami/keycloak:13.0.1-debian-10-r79
        env:
        - name: KEYCLOAK_USER
          valueFrom:
            secretKeyRef:
              name: keycloak-secret
              key: keycloak_user
        - name: KEYCLOAK_PASSWORD
          valueFrom:
            secretKeyRef:
              name: keycloak-secret
              key: keycloak_password
        - name: PROXY_ADDRESS_FORWARDING
          value: &quot;true&quot;
        - name: DB_VENDOR
          value: &quot;postgres&quot;
        - name: DB_ADDR
          value: &quot;my.postgres.host&quot;
        - name: DB_DATABASE
          value: &quot;keycloak&quot;
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: keycloak-secret
              key: dbuser
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: keycloak-secret
              key: dbpassword
        - name: KEYCLOAK_LOGLEVEL
          value: &quot;DEBUG&quot;
        - name: KEYCLOAK_EXTRA_ARGS
          value: &quot;-Dkeycloak.frontendUrl=https://my.keycloak.local/auth&quot;
        ports:
          - name: http
            containerPort: 8080
          - name: https
            containerPort: 8443
---
apiVersion: v1
kind: Service
metadata:
  name: keycloak
  labels:
    app: keycloak
spec:
  type: ClusterIP
  ports:
  - port: 8080
    name: http
    targetPort: 8080
  selector:
    app: keycloak
</code></pre>
<p>and my ingress.yaml:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.org/server-snippets: |
      location / {
        proxy_set_header X-Forwarded-For $host;
        proxy_set_header X-Forwarded-Proto $scheme;
      }
  name: ingress
spec:
  tls:
  - hosts:
      - my.keycloak.local
  rules:
  - host: my.keycloak.local
    http:
      paths:
      - path: &quot;/&quot;
        pathType: Prefix
        backend:
          service:
            name: keycloak
            port:
              number: 8080
</code></pre>
<p>I have no idea what I'm doing wrong here. I've followed some discussions on GitHub regarding this issue but I still can't find a solution. This particular configuartion that I provided is returning 404 not found when I access <a href="https://my.keycloak.local/auth" rel="nofollow noreferrer">https://my.keycloak.local/auth</a>.</p>
<p>What I can tell is that this is definitely an issue with keycloak - I substituted the keycloak image with a nginx:alpine docker image and everything is working correctly - the &quot;Welcome to nginx!&quot; page loads.</p>
<p>I'll gladly provide more info if needed. My kubernetes cluster is running on AKS.</p>

dywan666
<p>Well after reading the keycloak logs more carefully my problem is resolved. Turns out that keycloak doesn't start properly (even though the state of the pod was Running 1/1&quot;) if the pod name is longer than 23 characters. After changing Deployment resource to a StatefulSet and choosing a  ServiceName, my problems went away, keycloak started properly and I can access it.</p>
