<p>I am trying to deploy a pod in kubernetes and link a service to it so I can access it via web browser.</p>
<p>The pod specification is the following:</p>
<pre class="lang-yaml prettyprint-override"><code>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
</code></pre>
<p>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:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: visualizer-service
spec:
  type: NodePort
  selector:
    app: visualizer
  ports:
    - port: 8100
      targetPort: 8100
      nodePort: 30012
</code></pre>
<p>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.</p>
<p>If anyone is wondering, the app deployed is working fine, if I execute a port-forward (<code>microk8s kubectl port-forward pods/visualizer-nautic-77957b94c9-mww6p 8100:8100 </code>) I can then access the app working perfectly at localhost:8100.</p>
<p>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.</p>
<p>EDIT2: As requested, I leave specs and versions here:<br />
OS - Ubuntu 20.04 LTS<br />
Kubernetes - Microk8s 1.23</p>

<p>The nodeport is on your kubernetes node.
Accessing from your local machine wont work.
Use http://masternodeipaddress:nodeport.</p>
<p>You can add a hostentry in your local hosts file like:</p>
<pre><code>masternodeipaddress mytestdomain.local
</code></pre>
<p>then access <a href="http://mytestdomain.local:nodeport" rel="nofollow noreferrer">http://mytestdomain.local:nodeport</a>.</p>
<p>Update</p>
<p>With service type Loadbalancer. <br>
Get the IP from your masternode. <br>
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.</p>
<p>deployment.yaml</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: app
spec:
  ports:
    - name: tcp
      port: 80
      protocol: TCP
      targetPort: 80
  externalIPs: 
    - 10.165.39.165 # master node ip
  selector:
    app: app
  type: LoadBalancer


---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app
  name: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
        - image: nginx
          name: app
          ports:
            - containerPort: 80
              protocol: TCP
        
      restartPolicy: Always
</code></pre>
<p>with nodePort</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: app
spec:
  ports:
    - name: tcp
      port: 80
      protocol: TCP
      targetPort: 80
      nodePort: 31000 # optional, use kubectl get svc -o wide if you let it blank
  externalIPs: 
    - 10.165.39.165 # master node ip
  selector:
    app: app
  type: NodePort
</code></pre>
<p>To set a domain local:</p>
<pre><code>sudo vi /etc/hosts
</code></pre>
<p>add a line with masternode ip like:</p>
<pre><code>10.165.39.165 mydomain.local
</code></pre>
<p>Now you can access in your browser with</p>
<p><a href="http://mydomain.local" rel="nofollow noreferrer">http://mydomain.local</a></p>
<p>Note:
I have tested this with:
Ubuntu 22.04
multipass 3 nodes with microk8s 1.24
in microk8s dns ingress enabled.</p>
