How to add the hostname in microk8s to use a custom hostname

7/23/2020

I'm looking at microk8s to host my application and it will be using ingress. Currently it is deployed on AWS for development system and will be soon moved to an Onprem System

To access the application i have to simply provide the external hostname of AWS and it pulls the application page without any issue.

kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0

kubectl expose deployment web --type=NodePort --port=8080

web          NodePort    10.152.183.37    <none>        8080:30631/TCP   34m
web2         NodePort    10.152.183.226   <none>        8080:30881/TCP   25m

Now if i use the AWS hostname it is showing up as expected

Hello, world!
Version: 2.0.0
Hostname: web2-8474c56fd-kb8nx

So far everything works as expected. Now on Microk8s I have created an Ingress with the below details:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: http-ingress
spec:
  rules:
    - http:
      paths:
      - path: /
        backend:
          serviceName: web
          servicePort: 8080
      - path: /v2
        backend:
          serviceName: web2
          servicePort: 8080

This also works as expected.

Now is there a way i can mask the AWS hostname which is ec2-*--*-.us-east-2.compute.amazonaws.com to something that i would want to choose or customize. For example a3.myweb.com

I saw that this is possible in minikube/kubernetes using "host" attribute

What is the best way to mask the hostname of AWS/anyserver with a custom name????

Since we were using NGINX as a reverse proxy we were able to do it with providing the hostname in the conf.d/ssl.conf file

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
	
	server_name a1-staging.mycomp.com;
	
    ssl_certificate /etc/pki/tls/certs/a1.crt;
    ssl_certificate_key /etc/pki/tls/private/a1.key;

Can i achieve something similar in the micok8s setup with Ingress or anything else that the community suggest???

Thank you, Anish

-- anish anil
kubernetes
kubernetes-ingress
microk8s

1 Answer

7/23/2020

Ingress rules can have a host property

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: http-ingress
spec:
  rules:
    - host: 'a3.myweb.com'
      http:
        paths:
        - path: /
          backend:
            serviceName: web
            servicePort: 8080
        - path: /v2
          backend:
            serviceName: web2
            servicePort: 8080
-- Matt
Source: StackOverflow