来自带有 microk8s 的主机的简单入口? [英] Simple ingress from host with microk8s?

查看:25
本文介绍了来自带有 microk8s 的主机的简单入口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 MicroK8s 做两件事:

I would like to do two things with MicroK8s:

  1. 将主机 (Ubuntu 18.04) 端口 80/443 路由到 Microk8s
  2. 使用类似于 kubernetes.io<中定义的简单入口的东西/a> 文档

我的最终目标是创建一个位于 Ubuntu 主机上的单节点 Kubernetes 集群,然后使用 ingress 将不同的域路由到服务内各自的 pod.

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.

过去几天我一直在尝试用 Microk8s 来做这件事,但我无法理解它.

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.

我还启用了 default-http-backend 并尝试导出和编辑这些配置文件但没有成功.

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

举个例子,一旦启用了入口插件,这将在 Minikube 上工作,这个例子显示了集群 IP 上端口 80 的基本 Nginx 服务器镜像:

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

推荐答案

如果我理解正确,您可能会从以下几个方面来看待.

If I understood you correctly, there are a few ways you might be looking at.

一个是您已经提到的 MetalLB.

MetalLB 为不在受支持的云提供商上运行的 Kubernetes 集群提供网络负载平衡器实现,有效地允许在任何集群中使用 LoadBalancer 服务.

MetalLB provides a network load-balancer implementation for Kubernetes clusters that do not run on a supported cloud provider, effectively allowing the usage of LoadBalancer Services within any cluster.

详细实现可以阅读A纯软件方案:MetalLB

另一种方式是 超过一个节点端口服务

这种方法还有一些其他的限制,人们应该注意:

This approach has a few other limitations one ought to be aware of:

  • 源 IP 地址

NodePort 类型的服务执行 源地址转换 默认.这意味着从 NGINX 的角度来看,HTTP 请求的源 IP 始终是接收请求的 Kubernetes 节点的 IP 地址.

Services of type NodePort perform source address translation by default. This means the source IP of a HTTP request is always the IP address of the Kubernetes node that received the requestfrom the perspective of NGINX.

你也可以使用主机网络

在没有可用的外部负载平衡器但不能使用 NodePorts 的设置中,可以配置 ingress-nginx Pod 以使用它们运行的​​主机的网络而不是专用的网络命名空间.这种方法的好处是 NGINX Ingress 控制器可以将端口 80 和 443 直接绑定到 Kubernetes 节点的网络接口,而无需 NodePort 服务强加的额外网络转换.

In a setup where there is no external load balancer available but using NodePorts is not an option, one can configure ingress-nginx Pods to use the network of the host they run on instead of a dedicated network namespace. The benefit of this approach is that the NGINX Ingress controller can bind ports 80 and 443 directly to Kubernetes nodes' network interfaces, without the extra network translation imposed by NodePort Services.

你还要记住,如果你在POD里面编辑配置,如果Pod重启或崩溃,它就会消失.

You have to also remember that if you edit the configuration inside the POD, it will be gone if the Pod is restarted or it crashes.

我希望这能帮助您确定按照您的想法走哪条路.

I hope this helps you to determine which way to go with your idea.

这篇关于来自带有 microk8s 的主机的简单入口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆