<p>I have a local Kubernetes cluster based on <a href="https://microk8s.io/" rel="nofollow noreferrer">MicroK8s</a> running on an Ubuntu 18.04 machine.</p>

<p><strong>What I want to achieve:</strong> Generally I want to expose my applications to DNS names and test them locally.</p>

<p><strong>My setup:</strong> </p>

<p>I created the following test deployment </p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-app
  labels:
    app: hello-app
    tier: backend
    version: v1
spec:
  selector:
    matchLabels:
      app: hello-app
  replicas: 2
  template:
    metadata:
      labels:
        app: hello-app
    spec:
      containers:
      - name: hello-app
        image: localhost:5000/a-local-hello-image
        ports:
        - containerPort: 3000
</code></pre>

<p>I added the following service descriptor:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: hello-app
spec:
  selector:
    app: hello-app
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
</code></pre>

<p>Now I want to see my app available, let's say, at <code>http://hello.someurl.com:3000</code>.</p>

<p><strong>Question:</strong> What do I need to setup in addition to my current configuration to map my application to a DNS name locally?</p>

<p><strong>Note:</strong> I have read <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">the documentation</a> which unfortunately didn't help. I also <a href="https://microk8s.io/docs/addon-dns" rel="nofollow noreferrer">enabled DNS addon</a> on my cluster. </p>

<p>I would appreciate any help, any directions on how to move forward.</p>

Sasha Shpota
<p>You can create an Ingress resource, like the one below:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  tls:
  - secretName: tls 
  rules:
  - host: site1.domain.com
    http:
      paths:
      - path: /path1/
        backend:
          serviceName: service1
          servicePort: 80
      - path: /path2/
        backend:
          serviceName: service2
          servicePort: 8080
      - path: /
        backend:
          serviceName: service3
          servicePort: 80
  - host: site2.domain.com
    http:
      paths:
      - backend:
          serviceName: service1
          servicePort: 80
</code></pre>

<p>To make this work, you would need an Ingress Controller, like Nginx, Traefik, etc. </p>

<p>Once you have got Ingress Controller (if you haven't already), and have created the Ingress resource (the yaml above), you can forward the requests depending on the host and path to the desired service. As an example, if I would want to send traffic to <code>service2</code>, I would do:</p>

<p><code>curl -H "site1.domain.com/path2/" INGRESS_IP:INGRESS_PORT</code>. The request would go through the Ingress Controller, and it would deliver the packet to service2. If you modify the service name and port by yours, it should work fine.</p>

<p>You can also put it in <code>/etc/hosts</code>, of course.</p>

<p>And you could set up as many domains and paths as you wish in 1 singe ingress resource.</p>
