Simple ingress from host with microk8s?

后端 未结 4 2120
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 05:33

I would like to do two things with MicroK8s:

  1. Route the host machine (Ubuntu 18.04) ports 80/443 to Microk8s
  2. Use something like the simple ingress defi
4条回答
  •  暖寄归人
    2020-12-30 05:38

    The statement "The best I've gotten so far is using MetalLB to create a load balancer." is wrong. You must to use the ingress layer for host traffic routing.

    In a bare metal environment you need to configure MetalLB to allow incoming connections from the host to k8s.

    First we need a test:

    curl -H "Host: nginx.ioo" http://HOST_IP
    

    What is the result?

    1. Network error
    2. Error 404 or 503
    3. Works!!

    If Network error then you need MetalLB

    microk8s.enable metallb:$(curl ipinfo.io/ip)-$(curl ipinfo.io/ip) 
    

    Run the test again.

    If Network error then you have something wrong. Check host connectivity.

    If error 404 (sometimes 503) then you need a ingress rule.

    # 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
    

    Last test. It should work.

    Now you can use ingress to route different domains to their respective pods inside the service.

提交回复
热议问题