I am trying to expose Mariadb deployment using Nginx ingress.
Some of the references that I had look at so far, but could not resolve my problem are as follows.
https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md
Kubernetes 1.16 Nginx Ingress (0.26.1) TCP Mariadb/MySQL service not working
https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/
When I use nodeport instead of nginx ingress, I am able to connect.
But when I use nginx ingress, I am not able to connect.
I use the following three commands to get the port number of nginx controller.
INGRESSNODEPORTIP=$(kubectl get ingresses mariadb-ingress -o jsonpath='{ .status.loadBalancer.ingress[].ip }')
NODEPORT=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath='{ .spec.ports[?(@.name=="http")].nodePort }')
echo $INGRESSNODEPORTIP:$NODEPORT
I get the following ip and port.
162.187.99.102:31358
And when I try to connect, as you can see, it does not connect.
My manifests are as follows.
First the deployment manifest.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mariadb-deployment
spec:
replicas: 1
selector:
matchLabels:
appmariadbpods: ohr-maria-db-pods
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
appmariadbpods: ohr-maria-db-pods
spec:
containers:
- env:
- name: "ALLOW_EMPTY_PASSWORD"
value: "true"
- name: MARIADB_DATABASE
value: bitnami_orangehrm
- name: MARIADB_USER
value: bn_orangehrm
image: docker.io/bitnami/mariadb:10.3
name: mariadb-container
ports:
- containerPort: 3306
volumeMounts:
- mountPath: /bitnami/mariadb
name: mariadb-data
volumes:
- name: mariadb-data
persistentVolumeClaim:
claimName: maria-db-pvc
The Persistent Volume is as follows.
apiVersion: v1
kind: PersistentVolume
metadata:
name: maria-db-pv
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 2Gi
persistentVolumeReclaimPolicy: Retain
nfs:
server: 162.187.99.200
path: "/export/volumes/ohr-maria-db"
The Persistent Volume Claim is as follows.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: maria-db-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
The service is as follows
apiVersion: v1
kind: Service
metadata:
name: ohr-maria-db-service-ingress
spec:
selector:
appmariadbpods: ohr-maria-db-pods
ports:
- name: ohr-maria-db-ingress
port: 3306
protocol: TCP
targetPort: 3306
The config map.
apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: ingress-nginx
data:
3306: "default/ohr-maria-db-service-ingress:3306"
Finally the ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mariadb-ingress
spec:
defaultBackend:
service:
name: ohr-maria-db-service # hello-world-service-default
port:
number: 3306
The nginx controller is deployed using the deploy file here.
kubectl apply -f deploy.yaml
What baffles me is when I use nodeport, the service would instead look like this and this works!
apiVersion: v1
kind: Service
metadata:
name: ohr-maria-db-service
spec:
type: NodePort
selector:
appmariadbpods: ohr-maria-db-pods
ports:
- name: ohr-maria-db-nodeport
port: 3306
protocol: TCP
targetPort: 3306
nodePort: 30011
Why is my nginx ingress does not work? This is driving me nuts, any help would be deeply appreciated.