I have a simple flask process running on port 8080 in my container according my docker file
FROM python:3.7 RUN mkdir /app WORKDIR /app ADD . /app/ RUN pip install flask RUN pip install gunicorn CMD ["gunicorn", "-w", "1", "-b", ":8080", "-t", "360", "wsgi:app"]
and I created a deployment for the kubernetes cluster running on docker like this
apiVersion: v1 kind: Service metadata: name: hello-python-service spec: selector: app: hello-python ports: - protocol: "TCP" port: 6000 targetPort: 8080 nodePort: 30001 type: LoadBalancer --- apiVersion: apps/v1 kind: Deployment metadata: name: hello-python spec: replicas: 2 selector: matchLabels: app: hello-python template: metadata: labels: app: hello-python spec: containers: - name: hello-python image: hello-python:latest imagePullPolicy: Never ports: - containerPort: 8080
When I apply this deployment to kubernetes, which port am I supposed to use to access the service? When I tried localhost:6000, I was able to access the service. But that’s not what I expected because I was watching this video where a similar hello world service is deployed to kubernetes and the presenter access the service from a browser on port 30001
According to what I’ve read ( and also from that same video https://youtu.be/1xo-0gCVhTU?t=1607),
port is accessible inside cluster
targetPort is the port traffic for the service gets forwarded to inside the pod
nodePort is the port accessible outside the cluster
I guess I wasn’t expecting to access the service on port 6000 because port says its inside the cluster but am I outside the cluster? or is the cluster my my entire workstation?
when I run
kubectl get service --all-namespaces
I get this
NAMESPACE default NAME hello-python-service TYPE LoadBalancer CLUSTER-IP 10.102.195.223 EXTERNAL IP localhost PORT(S) 6000:30001/TCP
I’m not clear on the networking aspect of this in relation to my machine.