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

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

问题描述

我想对MicroK8做两件事:

I would like to do two things with MicroK8s:

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

我的最终目标是创建一个位于Ubuntu主机上的单节点Kubernetes集群,然后使用入口将不同的域路由到服务中各自的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.

  • 到目前为止,我最好的方法是使用 MetalLB 创建负载均衡器.但这要求我使用本地网络上可用的免费IP地址,而不要使用主机IP地址.

  • 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 .

One would be MetalLB which you already mentioned.

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

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

You can read the detailed implementation A pure software solution: MetalLB

另一种方法是在NodePort服务

Another way would be Over a NodePort Service

这种方法还有其他一些局限性,应该注意:

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

  • 源IP地址
  • Source IP address

类型为 NodePort 的服务执行

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.

您还可以使用主机网络

You can also use host network

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

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天全站免登陆