I am running my application on Kubernetes that was provided to me as a black box docker image that runs with a bunch of env vars, volume mounts and (a little more unconventionally) using host port. I discovered - with a lot of pain and sweat - as expected, I can't have more than one pod in my deployment if I ever wish to see the host port function again.
Two things are clear to me: 1. I need to add more pod replicas & 2. I can't use an ingress controller (need to have a separate external IP).
Other points of information are:
- I am using an external IP (quick solution is a LB service)
- When I enable host port on Kubernetes, everything works like a charm
- I am using a single tls certificate that is stored in the PVC that will be shared between my pods.
- When I disable host port, increase number of replicas and pretend it should work, the pods start running successfully, but the application can't be reached the way I reach it normally, as if it never hears what comes from the user through the loadbalancer (hence I thought setting up a NAT might have something to do with a solution??)
Things I tried:
- Use NodePort to expose the containerPort, and add replicas (& maybe then set up an ingress for loadbalancing). Problems with this: The port I am trying to map to the host is 80, and it's out range. I need to allow TCP and UDP through, which will require to create 2 separate services each with a different nodePort.
- Expose any possible port I can think of that might be used through a Loadbalancer service. Problem with this is that the user cannot reach the app for some reason.
My yaml files look something like the following:
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: x
name: x
labels:
app: x
spec:
replicas: 1
selector:
matchLabels:
app: x
template:
metadata:
labels:
app: x
spec:
# hostNetwork: true
containers:
- name: x
image: x
env:
...
volumeMounts:
...
ports:
- containerPort: 80
volumes:
...
imagePullSecrets:
- name: x
service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: x
namespace: x
name: x
spec:
type: LoadBalancer
loadBalancerIP: x
ports:
- name: out
port: 8081
targetPort: 8081
protocol: TCP
- name: node
port: 80
targetPort: 80
protocol: TCP
selector:
app: x
---
apiVersion: v1
kind: Service
metadata:
labels:
app: x
namespace: x
name: x
spec:
type: LoadBalancer
loadBalancerIP: x
ports:
- name: out
port: 8081
targetPort: 8081
protocol: UDP
- name: node
port: 80
targetPort: 80
protocol: UDP
selector:
app: x
Problem is, what is the best practice / solution to replace host port netwroking safely?