I am trying to deploy a pod in kubernetes and link a service to it so I can access it via web browser.
The pod specification is the following:
apiVersion: apps/v1
kind: Deployment
metadata:
name: visualizer-nautic
labels:
app: visualizer
spec:
replicas: 1
selector:
matchLabels:
app: visualizer
template:
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: zenoh-network
labels:
app: visualizer
spec:
containers:
- name: api
image: hielito/visualizer:latest
ports:
- containerPort: 8100
It deploys a web app, its frontend is exposed at port 8100, so then I add a NodePort service to make it visible in my network:
apiVersion: v1
kind: Service
metadata:
name: visualizer-service
spec:
type: NodePort
selector:
app: visualizer
ports:
- port: 8100
targetPort: 8100
nodePort: 30012
Once I have this service deployed, I try to access localhost:30012, but the web browser just gets stuck at loading and eventually throw a timeout error.
If anyone is wondering, the app deployed is working fine, if I execute a port-forward (microk8s kubectl port-forward pods/visualizer-nautic-77957b94c9-mww6p 8100:8100
) I can then access the app working perfectly at localhost:8100.
EDIT: I forgot to add that I am using multus CNI add-on and have a MACVLAN network interface added to the pod. When I remove the additional CNI it works fine again, so the MACVLAN network might be interfering with the service.
EDIT2: As requested, I leave specs and versions here:
OS - Ubuntu 20.04 LTS
Kubernetes - Microk8s 1.23
The nodeport is on your kubernetes node. Accessing from your local machine wont work. Use http://masternodeipaddress:nodeport.
You can add a hostentry in your local hosts file like:
then access http://mytestdomain.local:nodeport.
Update
With service type Loadbalancer.
Get the IP from your masternode.
I tried microk8s enable host-access, but had issues so i put the nodes ip address in externalIPs, as below. From the browser http://nmasternodeipaddress.
deployment.yaml
with nodePort
To set a domain local:
add a line with masternode ip like:
Now you can access in your browser with
http://mydomain.local
Note: I have tested this with: Ubuntu 22.04 multipass 3 nodes with microk8s 1.24 in microk8s dns ingress enabled.