I have created two PODs running in my minikube environment in windows 10. One POD with Spring boot application container and another POD with mysql container. For Spring boot application POD with service type is nodePort and for MYSQL pod, service with type is clusterIP. Means Mysql pod needs to communicate inside the cluster only. But for Spring boot application needs to access from browser so i configured NodePort.
i configured 30096 for NodePort. But i checked in my browser (minikube ip:nodePort).Its not working. So i try to execute the command "minikube service service-name" and output shows one different port(59870)
MYSQL_DEPLOYMENT_YML:
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: bcp-mysql
labels:
app: bcp-mysql
spec:
selector:
matchLabels:
app: bcp-mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: bcp-mysql
spec:
containers:
- image: <myrepo>/mysql:5.7
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: password
- name: MYSQL_DATABASE
value: database
- name: MYSQL_USER
value: root
- name: MYSQL_PASSWORD
value: password
ports:
- containerPort: 3306
name: mysql
imagePullPolicy: Always
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: Service
metadata:
name: bcp-mysql
spec:
selector:
app: bcp-mysql
ports:
- port: 3306
targetPort: 3306
type: ClusterIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: bcp-mysql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
Spring_boot_deployment.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: bcpdashboard
labels:
app: bcpdashboard
spec:
replicas: 1
selector:
matchLabels:
app: bcpdashboard
template:
metadata:
labels:
app: bcpdashboard
spec:
containers:
- name: app
image: <myrepo>/bcpdashboard:latest
ports:
- containerPort: 9097
imagePullPolicy: Always
env:
- name: SPRING_DATASOURCE_URL
value: jdbc:mysql://bcp-mysql:3306/bcp?autoReconnect=true&useSSL=false
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: Service
metadata:
name: bcpdashboard
spec:
selector:
app: bcpdashboard
ports:
- port: 9097
targetPort: 9097
nodePort: 30096
type: NodePort
---
My minikube ip is localhost IP only. So i try to run (http://127.0.0.1:30096). Its not working. So i try to execute "minikube service bcpdashboard"
And http://127.0.0.1:59870/ is working fine and i dont know about the port number 59870. How it is assigned automatically and start point to spring boot application POD even i configured nodeport.
Anyone face the same issue & please let me know how to make it work with nodePort and also is there any issues in deployment yaml configurations.
minikube ip
andhttp://<minikube ip>:30096
works or not? – hoquekubectl get svc
andminikube service bcpdashboard --url
? What do these print? – stackguy