<p>I would like to do two things with MicroK8s:</p>

<ol>
<li>Route the host machine (Ubuntu 18.04) ports 80/443 to Microk8s</li>
<li>Use something like the simple ingress defined in the <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-controllers" rel="noreferrer">kubernetes.io</a> docs</li>
</ol>

<p>My end goal is to create a single node Kubernetes cluster that sits on the Ubuntu host, then using ingress to route different domains to their respective pods inside the service.</p>

<p>I've been attempting to do this with Microk8s for the past couple of days but can't wrap my head around it. </p>

<ul>
<li><p>The best I've gotten so far is using <a href="https://github.com/google/metallb" rel="noreferrer">MetalLB</a> to create a load balancer. But this required me to use a free IP address available on my local network rather than the host machines IP address.</p></li>
<li><p>I've also enabled the <code>default-http-backend</code> and attempted to export and edit these config files with no success.</p></li>
</ul>

<p>As an example this will work on <code>Minikube</code> once the ingress add on is enabled, This example shows the base Nginx server image at port 80 on the cluster IP:</p>

<pre><code># ingress-service.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    # - host: nginx.ioo
    - http:
        paths:
          - path: /
            backend:
              serviceName: nginx-cluster-ip-service
              servicePort: 80
</code></pre>

<pre><code># nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: nginx
  template:
    metadata:
      labels:
        component: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
</code></pre>

<pre><code># nginx-cluster-ip-service

apiVersion: v1
kind: Service
metadata:
  name: nginx-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: nginx
  ports:
    - port: 80
      targetPort: 80
</code></pre>

denski
<h1>TLDR</h1>
<p>Update the annotation to be <code>kubernetes.io/ingress.class: public</code></p>
<h1>Why</h1>
<p>For MicroK8s v1.21, running</p>
<pre><code>microk8s enable ingress
</code></pre>
<p>Will create a <code>DaemonSet</code> called <code>nginx-ingress-microk8s-controller</code> in the <code>ingress</code> namespace.</p>
<p>If you inspect that, there is a flag to set the ingress class:</p>
<pre><code>      - args:
        ... omitted ... 
        - --ingress-class=public
        ... omitted ... 
</code></pre>
<p>Therefore in order to work with most examples online, you need to either</p>
<ol>
<li><strong>Remove</strong> the <code>--ingress-class=public</code> argument so it defaults to <code>nginx</code></li>
<li><strong>Update annotations</strong> like <code>kubernetes.io/ingress.class: nginx</code> to be <code>kubernetes.io/ingress.class: public</code></li>
</ol>
