kubernetesdeploymentserviceminikube

Can't access httpd deployment after exposing via service on browser on k8s playground


I am using labs.play-with-k8s.com. I created a small k8s cluster: 2 worker nodes, 1 master.

I have a deployment of 4 pods with httpd image running and exposed through service. I asked chatgpt how to hit the pods from outside - browser. It suggested port-foward cmd or 'kubectl proxy'. However to no results.

node2 is master node and 2 pods run on each worker node.

The deployment has containerPort as 77 and service has targetport 77, they do match. I choose it to be not-default 80 so I can check that using another port works and service properly exposes deployment through non-standard port.

Deployment yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: d
  name: d
spec:
  replicas: 2
  selector:
    matchLabels:
      app: d
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: d
    spec:
      containers:
      - image: httpd
        name: httpd
        ports:
        - containerPort: 77  

service is of type node port, exposes on nodeport 31399.

apiVersion: v1
kind: Service
metadata:
  name: d-service
spec:
  selector:
    app: d
  ports:
    - protocol: TCP
      port: 80
      targetPort: 77
      nodePort: 31399
  type: NodePort

Then I tried to hit with curl from outside into 1 worker node: 192.168.0.23 is IP of a worker node, 31399 is nodeport where service supposed to expose the deployment

curl 192.168.0.23:31399

It gives:

failed to connect, connection refused

I tried proxy forward and it did not work.

Does service only work with standard 80 ports?

kk


Solution

  • As mentioned in the comment provided by me, the sole reason for this issue is that the IP addresses provided by the playground are private IP addresses and those can’t be accessed outside the cluster of the playground. So, if you want to access your sample application via a browser, try to create VMs in any cloud provider or in your local device and replicate the cluster so that you can access the application via browser.