I have an error trying to deploy the official phpmyadmin
image locally in Kubernetes cluster. Please look at my yaml
configs. I haven't any idea what I did wrong. I tried phpmyadmin/phpmyadmin
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.
ingress-service.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- http:
paths:
- path: /phpmyadmin/?(.*)
pathType: Prefix
backend:
service:
name: phpmyadmin-cluster-ip-service
port:
number: 80
phpmyadmin-cluster-ip-service.yaml
apiVersion: v1
kind: Service
metadata:
name: phpmyadmin-cluster-ip-service
spec:
type: ClusterIP
selector:
app: phpmyadmin
ports:
- port: 80
targetPort: 80
protocol: TCP
phpmyadmin-deployment.yaml Ip 192.168.64.7 is given by minikube.
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: "http://192.168.64.7/phpmyadmin/"
- name: PMA_VERBOSE
value: "PhpMyAdmin"
- name: PMA_HOST
value: mysql-service
- name: PMA_PORT
value: "3306"
- name: UPLOAD_LIMIT
value: "268435456"
- name: PMA_ARBITRARY
value: "0"
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_ROOT_PASSWORD
I omitted MySQL yaml
configs thinking it doesn't related to phpmyadmin
issue but if they can help I will pushlish it too.
CodePudding user response:
Replace your path in your ingress resource from
/phpmyadmin/?(.*)
to
/phpmyadmin(/|$)(.*)
CodePudding user response:
I reproduced the problem on my machine (Minikube version v1.24.0
).
Adding the annotation nginx.ingress.kubernetes.io/rewrite-target: /$1
will fix the 404
problem you have described.
However, browsers have strict MIME type checking and apparently phpmyadmin resources fail the checks - and I am not sure if we can fix that if we don't have access to the source code. As a result, it is not possible to see the web page in your browser unless you disable MIME type checking and possibly other settings. Meanwhile, with curl http://$(minikube ip)/phpmyadmin
you can see the html returned (e.g., the forms, buttons etc...).
I assume you want to run your application locally in Kubernetes. Here are two options that do not use Ingress:
a) It is possible to run the application locally and use kubectl port-forward service/phpmyadmin-cluster-ip-service -n <NAMESPACE> 8000:80
and access your application on 127.0.0.1:8000
. Of course, you can replace 8000
with any other port that makes sense. This uses a kubectl command, and you may not want to do this every time you deploy your app.
b) Change your service
to type of NodePort
:
apiVersion: v1
kind: Service
metadata:
name: phpmyadmin-cluster-ip-service
spec:
type: NodePort
selector:
app: phpmyadmin
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
nodePort: 32500
The port 32500
is arbitrary - as long as you choose one between 30000 and 32767. You can then access it from echo http://$(minikube ip):32500
.
The disadvantage here is that you need to remember the node port number you set earlier when deploying the application.