Make sure you are familiar with connecting to a Kubernetes cluster, have the Nginx ingress controller configured with a certificate manager, and have a MySQL database pod deployed. Only then, can you proceed. Follow this guide if you do not have MySQL deployed. Follow this guide to set up Nginx ingress and cert manager.
PhpMyAdmin is a popular open source tool to manage MySQL database server. Learn how to create a deployment and expose it as a service to access PhpMyAdmin from the internet using Nginx ingress controller.
- Create a deployment file called phpmyadmin-deployment.yaml and paste the following values:
apiVersion: apps/v1
kind: Deployment
metadata:
name: phpmyadmin-deployment
labels:
app: phpmyadmin
spec:
replicas: 1
selector:
matchLabels:
app: phpmyadmin
template:
metadata:
labels:
app: phpmyadmin
spec:
containers:
- name: phpmyadmin
image: phpmyadmin/phpmyadmin
ports:
- containerPort: 80
env:
- name: PMA_HOST
value: mysql-service
- name: PMA_PORT
value: "3306"
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secrets
key: ROOT_PASSWORD
NOTE:
ROOT_PASSWORD
value will be consumed from Kubernetes secrets. If you want to learn more about Kubernetes secrets. Follow this guide.
- Execute the below command to create a new deployment:
kubectl apply -f phpmyadmin-deployment.yaml
Output:
deployment.apps/phpmyadmin-deployment created
Exposing PhpMyAdmin via Services
- Create new file called
phpmyadmin-service.yaml
and paste the following values:
apiVersion: v1
kind: Service
metadata:
name: phpmyadmin-service
spec:
type: NodePort
selector:
app: phpmyadmin
ports:
- protocol: TCP
port: 80
targetPort: 80
- Execute the below command to create service:
kubectl apply -f phpmyadmin-service.yaml
Output:
service/phpmyadmin-service created
Once you are done with the above configurations, it’s time to exposePhpMyAdminn service via internet.
I use DigitalOcean-managed Kubernetes. I manage my own DNS, and DigitalOcean automatically creates a load balancer for my Nginx ingress controller. Once again if you want to follow this guide, it will be very helpful.
Nginx Ingress configuration
- Create a new YAML file called phpmyadmin-ingress.yaml and paste the following values:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: echo-ingress
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
tls:
- hosts:
- phpmyadmin.example.com
secretName: echo-tls
rules:
- host: mydemo.example.com
http:
paths:
- backend:
serviceName: phpmyadmin-service
servicePort: 80
- Apply the changes:
kubectl apply -f mydemo-ingress.yaml