kind - exposing service to host

1/24/2022

I would like to run an application in local cluster for development purposes with kind using docker. Based on the description https://kind.sigs.k8s.io/docs/user/quick-start/ I defined the cluster

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
  extraPortMappings:
    - containerPort: 30000
      hostPort: 5432
      protocol: TCP

and the deployment with container:

        containers:
        - name: postgres
          image: postgres:14.0
          ports:
            - containerPort: 5432

and the service

apiVersion: v1
kind: Service
metadata:
  name:  database
spec:
selector:
  name:  app
type:  NodePort
ports:
- name:  postgres
  port:  5432
  targetPort:  5432
  nodePort: 30000

which I assumed should allow me to connect with dbeaver from my windows 11 host. This looks to be not working so I would like to ask, how should I configure that to being able to access it from host. What I have already tried is: localhost:30000, 127.0.0.1:30000 and also 127.0.0.1:5432, localhost:5432

Also kubectl get services command tells me that:

Type: NodePort, Port(S): 5432:30000/TCP, External-IP: <none>, Cluster-Ip:10.96.211.69, name:something

-- Puchacz
kind
kubernetes

1 Answer

1/25/2022

I found a solution, I turned out to be that I placed extractPortMappings inside worker node instead of control-plane. It's weird that it doesn't fail but after moving this part to correct place it started to work!

So the solution is to change to this:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30000
    hostPort: 5432
    protocol: TCP
- role: worker
-- Puchacz
Source: StackOverflow