<p>I have an error trying to deploy the official <code>phpmyadmin</code> image locally in Kubernetes cluster. Please look at my <code>yaml</code> configs. I haven't any idea what I did wrong. I tried <code>phpmyadmin/phpmyadmin</code> image but the 404 error stays. I also viewed configs from other people but it doesn't differ from mine. This is my first experience in Kubernetes so maybe I don't know some development approaches.</p>
<p><a href="https://i.stack.imgur.com/Cl7mI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cl7mI.png" alt="enter image description here" /></a></p>
<p>ingress-service.yaml</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  rules:
    - http:
        paths:
          - path: /phpmyadmin/?(.*)
            pathType: Prefix
            backend:
              service:
                name: phpmyadmin-cluster-ip-service
                port:
                  number: 80
</code></pre>
<p>phpmyadmin-cluster-ip-service.yaml</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: phpmyadmin-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    app: phpmyadmin
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
</code></pre>
<p>phpmyadmin-deployment.yaml Ip 192.168.64.7 is given by minikube.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpmyadmin-deployment
  labels:
    tier: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: phpmyadmin
      tier: backend
  template:
    metadata:
      labels:
        app: phpmyadmin
        tier: backend
    spec:
      restartPolicy: Always
      containers:
        - name: phpmyadmin
          image: phpmyadmin:latest
          ports:
            - name: phpmyadmin
              containerPort: 80
              protocol: TCP
          imagePullPolicy: Always
          env:
            - name: PMA_ABSOLUTE_URI
              value: &quot;http://192.168.64.7/phpmyadmin/&quot;
            - name: PMA_VERBOSE
              value: &quot;PhpMyAdmin&quot;
            - name: PMA_HOST
              value: mysql-service
            - name: PMA_PORT
              value: &quot;3306&quot;
            - name: UPLOAD_LIMIT
              value: &quot;268435456&quot;
            - name: PMA_ARBITRARY
              value: &quot;0&quot;
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: MYSQL_ROOT_PASSWORD
</code></pre>
<p>I omitted MySQL <code>yaml</code> configs thinking it doesn't related to <code>phpmyadmin</code> issue but if they can help I will pushlish it too.</p>

Sergey Filipovich
<p>In this case, adding the annotation <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/" rel="nofollow noreferrer"><code>nginx.ingress.kubernetes.io/rewrite-target: /$1</code></a> will fix it. How? (<em>NOTE: I will change service port to <code>8080</code> to better distinguish the ports of the <code>container</code> and <code>Service</code></em>).</p>
<ol>
<li>You visit <code>http://&lt;MINIKUBE IP&gt;/phpmyadmin/</code> on your browser.</li>
<li>The NGINX Ingress controller receives your request, and rewrites the path <code>/phpmyadmin/</code> to <code>/</code>. The NGINX Ingress controller creates the request to the <code>Service</code> in <code>phpmyadmin-cluster-ip-service</code> at port <code>8080</code> (service port) which has the <code>targetPort</code> at <code>80</code> (container port) for the pods containing the label <code>app: phpmyadmin</code>. One of the matching pods happens to be at <code>172.17.0.4</code>:</li>
</ol>
<pre><code>&quot;GET /phpmyadmin/favicon.ico HTTP/1.1&quot; 200 22486 &quot;-&quot; ... 492 0.001 [default-phpmyadmin-cluster-ip-service-8080] [] 172.17.0.4:80 22486 0.000 200 ...
</code></pre>
<ol start="3">
<li>Because the request is now using the correct path for the <code>phpmyadmin</code> server, it responds with <code>200</code> and the requested resource. We can also see the corresponding logs in phpmyadmin:</li>
</ol>
<pre><code>172.17.0.3 - - [14/Nov/2022:21:58:43 +0000] &quot;GET /favicon.ico HTTP/1.1&quot; 200 22733 &quot;-&quot; ...
</code></pre>
<p>The IP <code>172.17.0.3</code> is of the NGINX Ingress Controller.</p>
<p>There is also a similar <a href="https://stackoverflow.com/questions/61541812/ingress-nginx-how-to-serve-assets-to-application">question</a> with an even more detailed answer.</p>
