I want to expose my Mariadb pod using Nginx ingress TCP service by following this step https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/. Mariadb running in default name space, with mariadb service type as ClusterIP. I am running Nginx Ingress controller in nginx-ingress namespace, also defined tcp-services
cofigmap for mariadb
service. But I am unable to connect MariaDB database from outside of the cluster.
From Nginx controller log I can see its reading tcp-services.
Ingress configuration
containers:
- args:
- /nginx-ingress-controller
- --default-backend-service=nginx-ingress/nginx-ingress-default-backend
- --election-id=ingress-controller-leader
- --ingress-class=nginx
- --configmap=nginx-ingress/nginx-ingress-controller
- --default-ssl-certificate=nginx-ingress/ingress-tls
- --tcp-services-configmap=nginx-ingress/tcp-services
- --udp-services-configmap=nginx-ingress/udp-services
ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: nginx-ingress
data:
3306: "default/mariadb:3306"
Ingress controller nginx config for TCP Service
# TCP services
server {
preread_by_lua_block {
ngx.var.proxy_upstream_name="tcp-default-mariadb-3306";
}
listen 3306;
proxy_timeout 600s;
proxy_pass upstream_balancer;
}
when I connect from external server, getting this message:
ERROR 2002 (HY000): Can't connect to MySQL server on
any tips to troubleshoot this issue?
thanks
I was missing my service with TCP Port info, after adding it I was able to access the MySQL with my service Port Number. Thanks for Emanuel Bennici
pointing this one out.
Here is my service:
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress-controller
spec:
externalTrafficPolicy: Cluster
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
- name: https
port: 443
protocol: TCP
targetPort: https
- name: 3066-tcp
port: 3066
protocol: TCP
targetPort: 3066-tcp
selector:
app: nginx-ingress
component: controller
release: nginx-ingress
sessionAffinity: None
type: NodePort
kubectl run mariadb-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mariadb:10.3.20-debian-9-r19 --namespace default --command -- bash
– sfgroups