I have installed Nginx Controller using helm.
I have simple microservice application that I want to access externally via ingress controller.
Below
kind: Service
apiVersion: v1
metadata:
name: springboot-service
labels:
name: springboot-k8s-mysql
spec:
ports:
- nodePort: 30163
port: 8081
targetPort: 8080
protocol: TCP
selector:
app: springboot-k8s-mysql
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-deployment
spec:
selector:
matchLabels:
app: springboot-k8s-mysql
replicas: 1
template:
metadata:
labels:
app: springboot-k8s-mysql
spec:
containers:
- name: springboot-k8s-mysql
image: basharat1640/springboot-kube-mysql:latest
ports:
- containerPort: 8080
env: # Setting Enviornmental Variables
- name: MYSQL_HOST # Setting Database host address from configMap
valueFrom:
configMapKeyRef:
name: db-conf # name of configMap
key: host
- name: DB_NAME # Setting Database name from configMap
valueFrom:
configMapKeyRef:
name: db-conf
key: name
- name: DB_USERNAME # Setting Database username from Secret
valueFrom:
secretKeyRef:
name: mysql-secret # Secret Name
key: username
- name: DB_PASSWORD # Setting Database password from Secret
valueFrom:
secretKeyRef:
name: mysql-secret
key: password
Ingress Resource File is given below
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
ingressClassName: sample-nginx
ingress.kubernetes.io/ingress.allow-http: "false"
name: nginx-rules
namespace: default
spec:
rules:
- host: test.com
http:
paths:
- path: /GetAllUsers
pathType: Exact
backend:
service:
name: springboot-service
port:
number: 8081
I mapped the machine’s ip address with a host name in /etc/hosts file and that host name i used as host in the above ingress resource file. Now I’m trying to access my application through this host name. but it is not getting.