1

I have a k8s cluster where I deploy some containers.

The cluster is accessible at microk8s.hostname.internal.

At this moment I have an application/container deployed that is accessible here: microk8s.hostname.internal/myapplication with the help of a service and an ingress.

And this works great.

Now I would like to deploy another application/container but I would like it accessible like this: otherapplication.microk8s.hostname.internal.

How do I do this?

Currently installed addons in microk8s:

aasa@bolsrv0891:/snap/bin$ microk8s status
microk8s is running
high-availability: no
addons:
  enabled:
    dashboard            # (core) The Kubernetes dashboard
    dns                  # (core) CoreDNS
    helm                 # (core) Helm - the package manager for Kubernetes
    helm3                # (core) Helm 3 - the package manager for Kubernetes
    ingress              # (core) Ingress controller for external access
    metrics-server       # (core) K8s Metrics Server for API access to service metrics

Update 1: If I portforward to my service it works. I have tried this ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  namespace: jupyter-notebook
  annotations:
    kubernetes.io/ingress.class: public
spec:
  rules:
  - host: jupyter.microk8s.hostname.internal
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: jupyter-service
            port:
              number: 7070

But I cant access it nor ping it. Chrome says: jupyter.microk8s.hostname.internal’s server IP address could not be found.

My service looks like this:

apiVersion: v1
kind: Service
metadata:
  name: jupyter-service
  namespace: jupyter-notebook
spec:
  ports:
  - name: 7070-8888
    port: 7070
    protocol: TCP
    targetPort: 8888
  selector:
    app: jupyternotebook
  type: ClusterIP
status:
  loadBalancer: {}

I can of course ping microk8s.hostname.internal.

Update 2:

The ingress that is working today that has a context path: microk8s.boliden.internal/myapplication looks like this:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: public
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: jupyter-ingress
  namespace: jupyter-notebook
spec:
  rules:
    - http:
        paths:
          - path: "/jupyter-notebook/?(.*)"
            pathType: Prefix
            backend:
              service:
                name: jupyter-service
                port:
                  number: 7070

This is accessible externally by accessing microk8s.hostname.internal/jupyter-notebook.

Viktor Eriksson
  • 5,677
  • 3
  • 20
  • 24

2 Answers2

2

To do this you would have to configure a kube service, kube ingress and the configure your DNS.

Adding an entry into the hosts file would allow DNS resolution to otherapplication.microk8s.hostname.internal

You could use dnsmasq to allow for wildcard resolution e.g. *.microk8s.hostname.internal

You can test the dns reoslution using nslookup or dig

Wayne Shelley
  • 992
  • 10
  • 25
1

You can copy the same ingress and update name of it and Host inside it, that's all change you need.

For ref:

kind: Ingress
metadata:
  name: second-ingress <<- make sure to update name else it will overwrite  if the same
spec:
  rules:
  - host: otherapplication.microk8s.hostname.internal
    http:
      paths:
      - path: /
        backend:
          serviceName: service-name
          servicePort: service-port

You can create the subdomain with ingress just update the Host in ingress and add the necessary serviceName and servicePort to route traffic to specific service.

Feel free to append the necessary fields, and annotation if any to the above ingress from the existing ingress which is working for you.

If you are running it locally you might have to map the IP to the subdomain locally in /etc/hosts file

/etc/hosts

otherapplication.microk8s.hostname.internal <IP address>
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Thanks but I have already tried that. I have not done the hosts-thing but I'm not accessing it locally. pls check update :) – Viktor Eriksson Jan 13 '23 at 12:10
  • Microk8s is installed on a ubuntu machine. Is there anything in ubuntu that needs to be correctly configured? – Viktor Eriksson Jan 13 '23 at 13:23
  • not sure what you mean by hosts-thing, but if you have not updated or map the `/etc/hosts` files thn that's the issue you won't be able to get in chrome. that's the main point. – Harsh Manvar Jan 13 '23 at 13:25
  • I thought you said that it was only necessary if running locally, which I am not doing. But I added this row to the /etc/hosts-file: 10.161.64.124 jupyter.microk8s.hostname.internal where 10.161.64.124 is the ip of the k8s-machine. But I cant access anything from the outside. If I do wget from linux shell from k8s-machine on jypyter.microk8s.hostname.internal it seems to work, it downloads the index-page from the correct application. But how do I make jupyter.microk8s.hostname.internal accessible from the outside? – Viktor Eriksson Jan 13 '23 at 13:42
  • 1
    when you say outside mean on chrome browser on which your micro k8s running ? or outside mean over internet ? and your micro k8s running on some VM or bare metal? – Harsh Manvar Jan 13 '23 at 14:05
  • Its a private network the k8s server is not the same machine that i run chrome on. The k8s is on a vm. – Viktor Eriksson Jan 13 '23 at 14:43
  • Noted that, weird…! so with old ingress how’s your dns mapping set ? Existing ingress domain is exposed without any mapping required ? You can directly access existing ingress to chrome ? – Harsh Manvar Jan 13 '23 at 15:17
  • I can access the ingress directly with chrome. I updated my question with the old ingress that works but is in the format microk8s.hostname.internal/myapplication. I have read stuff about coredns, the dns that is distributed with microk8s. Does anything need to be changed in that one? – Viktor Eriksson Jan 13 '23 at 16:15
  • yes you are but only thing i am not getting is, your microk8s is running on ubuntu VM, and you are trying the URL on chrome from another machine, how it's resolving the DNS when you hit the host or URL. `microk8s.hostname.internal` your chrome machine how reach to this one as it's whole diff machine, without using metallb or nothing so doubt. – Harsh Manvar Jan 13 '23 at 16:36
  • Well my client has an internal dns. And I ordered the dns-name microk8s.hostname.internal for the k8s-server. But maybe I have misunderstood what is possible here. Do I need to order a new name for each of the ingresses that will use the host-property? So I need to order a dns-name called otherapplication.microk8s.hostname.internal. Or perhaps it is possible to order *.microk8s.hostname.internal. – Viktor Eriksson Jan 16 '23 at 07:04
  • 1
    Yes definitely you have to do that or else use *.domain.com so any traffic on xyz.domain.com will come to cluster and you have route in ingress handle it by host name or path etc – Harsh Manvar Jan 16 '23 at 07:07