-1

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.

  1. https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/exposing-tcp-udp-services.md

  2. Why ingress-nginx controller tcp-services not working?

  3. Kubernetes 1.16 Nginx Ingress (0.26.1) TCP Mariadb/MySQL service not working

  4. 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.

Not able to connect to maria db What am I missing?

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.

VivekDev
  • 20,868
  • 27
  • 132
  • 202

1 Answers1

1

if you check the node port which you got from the nginx is

162.187.99.102:31358

port is 31358 can you please let me know mapping when the request comes on ingress should go to Database?

while for the service, there is a direct mapping of the port number you can see target port and port.

also, command you are firing

INGRESSNODEPORTIP=$(kubectl get ingresses mariadb-ingress -o jsonpath='{ .status.loadBalancer.ingress[].ip }')

this will be giving the LoadBalancer IP I think that load Balancer will be HTTP load balancer by default.

NODEPORT=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath='{ .spec.ports[?(@.name=="http")].nodePort }')

this is the node port you are getting but Node will only work with IP of slave nodes or work node not with the Load balancer that ingress has created.

echo $INGRESSNODEPORTIP:$NODEPORT
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102