Is it possible for outside traffic to access my deployment inside Minikube?

9/11/2019

Kubernetes newbie here. Just want to get my fundamental understanding correct. Minikube is known for local development and is it possible for connection outside (not just outside cluster) to access the pods I have deployed in minikube?

I am running my minikube in ec2 instance so I started my minikube with command minikube start --vm-driver=none, which means running minikube with Docker, no VM provisioned. My end goal is to allow connection outside to reach my pods inside the cluster and perform POST request through the pod (for example using Postman).

If yes, I also have my service resource applied using kubectl apply -f into my minikube using NodePort in yaml file. Also, I also wish to understand port, nodePort, and targetPort correctly. port is the port number assigned to that particular service, nodePort is the port number on the node (in my case is my ec2 instance private IP), targetPort is the port number equivalent to the containerPort I've assigned in yaml of my deployment. Correct me if I am wrong in this statement.

Thanks.

-- rick
kubernetes
minikube

1 Answer

9/11/2019

Yes you can do that

as you have started the minikube with :

minikube start --vm-driver=none

nodePort is the port that a client outside of the cluster will "see". nodePort is opened on every node in your cluster via kube-proxy. You can use nodePort to access the application from outside world. Like https://loadbalancerIP:NodePort

port is the port your service listens on inside the cluster. Let's take this example:

apiVersion: v1
kind: Service
metadata:
  name: test-service
spec:
  ports:
  - port: 8080
    targetPort: 8070
    nodePort: 31222
    protocol: TCP 
  selector:
    component: test-service-app

From inside k8s cluster this service will be reachable via http://test-service.default.svc.cluster.local:8080 (service to service communication inside your cluster) and any request reaching there is forwarded to a running pod on targetPort 8070.

tagetPort is also by default the same value as port if not specified otherwise.

-- Harsh Manvar
Source: StackOverflow