本文介绍了有兴趣使用Minikube&在EC2实例上设置K8s集群.域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于个人工作的EC2实例&流量很小的项目(投资组合等).

I have an EC2 instance that I use for personal work & projects with very small amounts of traffic (portfolio, etc).

我认为使用Minikube设置运行我的各个项目的开发集群并将域名连接到该实例真的很酷(虽然显然是过分杀伤了).

I thought it'd be really cool (although obviously overkill) to set up a dev cluster running my various projects using Minikube and to connect a domain name to this instance.

我有一个指向我的服务的Ingress控制器,其IP地址与主机不同.我认为这是VM的IP地址,但只能从主机访问.

I have an Ingress controller that points to my service, with an IP address that is different than the host machine. I think it's somehow the IP address of the VM, but only accessible from the host machine.

我真的很想使用Ingress,因为我有多个使用不同域名运行的项目.看起来像简单的&根据我的有限知识正确的解决方案.

I'd really like to use Ingress because I have a number of projects running with different domain names in use. Seems like the simple & correct solution based on my limited knowledge.

对k8s/网络了解不多,我不知道如何使外部流量访问分配给我的实例的弹性IP,并将其定向到Ingress控制器

Not knowing much about k8s/networking, I don't know how to get external traffic visiting the elastic IP assigned to my instance to be directed to the Ingress controller

我当时在想,因为这实际上仅用于开发目的,所以我可以尝试以某种方式使用kubect port-forward ...指向我的Ingress控制器.但是 port-forward来自官方网站的参考什么也没说Ingress控制器.

I was thinking that, since this is really only going to be used for dev purposes, that I could try using kubect port-forward ... somehow to point to my Ingress controller. But this port-forward reference from the official website says nothing about Ingress controllers.

通过Ingress控制器将外部流量吸引到群集中的最正确方法是什么?

What is the most correct way to get external traffic into my cluster via an Ingress controller?

推荐答案

假设这不是针对实际生产工作负载的,我建议采用以下方法

Assuming this is not for real production workload I would suggest below approach

  1. 使用 kubeadm 在EC2实例上安装一个单节点kubernetes集群.

  1. Instead of using minikube use kubeadm to install a single node kubernetes cluster on the EC2 instance.

确保除去主节点污点,以便可以在主节点上计划工作负载Pod,这意味着同一EC2实例将托管控制平面Pod和工作负载Pod.命令是

Make sure to remove the master node taint so that workload pods can be scheduled on the master node meaning the same EC2 instance will host control plane pods as well as workload pods. Command for that is

kubectl taint nodes nodename node-role.kubernetes.io/master:NoSchedule-

安装nginx入口控制器,并在部署yaml中使用hostNetwork: true.因此,nginx将在端口80443上侦听EC2实例的网络.这是上的文档.

Install nginx ingress controller and use hostNetwork: true in the deployment yaml. So nginx will listen to the EC2 instance's network on port 80 and 443. Here is the doc on this.

创建入口资源,您可以通过EC2实例的公共IP地址访问任何服务.

Create ingress resource and you can access any service via EC2 instances public IP address.

当您有更多EC2实例的预算时,可以使用kubeadm join将这些实例作为工作节点添加到群集中.

When you have budget for more EC2 instance you can add those as worker nodes to the cluster using kubeadm join.

注意:您可以将EC2层实例的免费t2.micro用作工作程序节点.

Note: You can use free t2.micro which is tier EC2 instance as worker nodes.

这篇关于有兴趣使用Minikube&在EC2实例上设置K8s集群.域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:05