Test Pod's external IP on a Kubernetes one node cluster

6/29/2021

I am working with the docker desktop version and have got a one node Kubernetes cluster. I have a containerized web api that is represented by the pod.

I want to give the Pod an IP adress other than the localhost.

I created a service to expose my pod and used an external IP, here is the yaml file :

apiVersion: v1
kind: Service
metadata:
  name: pred-entrypoint
  namespace: default
spec:
  type: LoadBalancer
  selector:
    app: predictim
  ports:
  - port: 1080
    targetPort: 1080
    nodePort: 30001
  externalIPs:
    - 80.11.12.10

When I launch a service describe I get as external IPs : localhost, 80.11.12.10

When I test the pod with PowerShell :

  • using Invoke-RestMethod -Method POST -Uri http://localhost:1080/predict --> it works fine
  • using Invoke-RestMethod -Method POST -Uri http://80.11.12.10:1080/predict --> bad address error

I don't know how to do test the assigned External-IP.

I'm certainly missing something, can you please help me to understand. Thank you so much in advance.

-- Doudda
docker
kubernetes
webapi

1 Answer

6/29/2021

Easiest way to achieve is to use hostPort. This will basically mimic the -p 1080:1080 option on docker run command. You should be able to use your public IP too since it's only one node. This has to be done in pod template.

ports:
- containerPort: 1080
  hostPort: 1080

A more elegant way is using MetalLB. With MetalLB installed you can just make your service type LoadBalancer even if you are not on cloud.

-- Akin Ozer
Source: StackOverflow