Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

kubernetes - Simple ingress from host with microk8s?

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 defined in the kubernetes.io docs

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.

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

  • The best I've gotten so far is using MetalLB 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.

  • I've also enabled the default-http-backend and attempted to export and edit these config files with no success.

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

# 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
# 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
# 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

TLDR

Update the annotation to be kubernetes.io/ingress.class: public

Why

For MicroK8s v1.21, running

microk8s enable ingress

Will create a DaemonSet called nginx-ingress-microk8s-controller in the ingress namespace.

If you inspect that, there is a flag to set the ingress class:

      - args:
        ... omitted ... 
        - --ingress-class=public
        ... omitted ... 

Therefore in order to work with most examples online, you need to either

  1. Remove the --ingress-class=public argument so it defaults to nginx
  2. Update annotations like kubernetes.io/ingress.class: nginx to be kubernetes.io/ingress.class: public

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...