Exposing ports externally

11/1/2021

I'm deploying an IRC server where I need to expose port 6667 to external networks. The application pod itself works internally with port 6667.

I'm currently using minikube/kubectl in my host machine

This is my YAML configuration file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: inspircd-x
spec:
  selector:
    matchLabels:
      app: inspircd
  replicas: 2
  template:
    metadata:
      labels:
        app: inspircd
    spec:
      containers:
      - name: inspircd-x
        image: inspircd/inspircd-docker
        ports:
        - containerPort: 6667

i'm creating a Service:

kubectl expose deployment inspircd-x --type=LoadBalancer --name inspircd-x

and assigning an IP:

minikube service inspircd-x

I know that NodePort range is 30000 - 32767, so (obviously) when i try to modify my service configuration it throws an error.

What i want to do is similar to this docker yaml:

services:
  ircd-compose:
    image: inspircd/inspircd-docker
    ports:
      - 6667:6667
      - 7000:7000

I think there are concepts that I misunderstood when it comes to configuration so i got a couple of question:

1) will the expose command and "minikube service inspircd-x" assign an external IP which can be accessed from outside? (I could do it with Docker, pointing my router to my host machine). Certainly, the ip that appears below is not within the IP range of my local network (192.168.0.x)

| NAMESPACE |    NAME    | TARGET PORT |            URL            |
|-----------|------------|-------------|---------------------------|
| default   | inspircd-x |        6667 | http://192.168.64.2:30047 |

2) is this the correct way to expose my pod externally?

Thanks!

-- emboole
kubernetes
kubernetes-service
minikube

1 Answer

11/1/2021

The equivalent of your docker-compose file would be using a host port on the node. As you are using minikube this is only a single node anyway.

    spec:
      containers:
      - name: inspircd-x
        image: inspircd/inspircd-docker
        ports:
        - containerPort: 6667
          hostPort: 6667

A kubernetes service is for connectivity inside the cluster, it can be exposed externally using additional services, usually provided as part of the infrastructure, like a LoadBalancer

Your next question, if that is the correct way to do it - it depends. Since the hostPort is only available to a single pod, you won't be able to do rolling deployments.

-- Thomas
Source: StackOverflow