2
votes

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)

enter image description here

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

enter image description here

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"

enter image description here

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. enter image description here

enter image description here enter image description here

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.

1
Can you check minikube ip and http://<minikube ip>:30096 works or not?hoque
my minikube ip is 127.0.0.1 and its not working with nodePort(30096)A.S.karthick
Did you try running kubectl get svc and minikube service bcpdashboard --url? What do these print?stackguy
@stackguy - I have attached screenshot. Please check itA.S.karthick
By default , the nodePort that will be automatically assigned to the cluster is in the range 30000-32767.Have you done any changes in cluster configuration to change this range?sachin

1 Answers

1
votes

Seems like the behavior is specific to your setup of minikube, using your deployment yaml in my setup, everything functions as it's stated, i.e. only curl http://127.0.0.1:30096/ responds w/ 200.

I used helloworld-http as the image, and k8s 16 w/ docker-desktop 2.3. The deployment yaml looks something this:

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: strm/helloworld-http
          ports:
            - containerPort: 80
          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: 80
      targetPort: 80
      nodePort: 30096
  type: NodePort
---

Have you tried using docker-windows-desktop-kubernetes ? You could give that a try, it will atleast isolate the problem for you.