简体   繁体   English

如何在不使用 ELB 服务的情况下使用 kops 在 AWS 上创建 Kubernetes 集群?

[英]How to use kops to create a Kubernetes cluster on AWS without the usage of the ELB service?

I'm just learning Kubernetes and I'd like to avoid spending money on Elastic Load Balancing while running it on AWS.我只是在学习 Kubernetes,我想避免在 AWS 上运行 Elastic Load Balancing 时花钱。

Here's the command I use to install Kubernetes:这是我用来安装 Kubernetes 的命令:

kops create cluster \
    --cloud aws \
    --name ${MY_KUBE_NAME}.k8s.local \
    --state s3://${MY_KUBE_NAME} \
    --master-count 1 \
    --master-size ${MY_KUBE_MASTER_AWS_INSTANCE_SIZE} \
    --master-volume-size ${MY_KUBE_MASTER_AWS_VOLUME_SIZE} \
    --master-zones ${MY_KUBE_AWS_ZONE} \
    --zones ${MY_KUBE_AWS_ZONE} \
    --node-count 1 \
    --node-size ${MY_KUBE_WORKER_AWS_INSTANCE_SIZE} \
    --node-volume-size ${MY_KUBE_WORKER_AWS_VOLUME_SIZE}

After running that command I can see a load balancer gets created through Amazon's ELB service.运行该命令后,我可以看到通过 Amazon 的 ELB 服务创建了一个负载均衡器。

Generally, that all worked well for me and then I could use kubectl to monitor and manage my cluster and also install Kubernetes Dashboard with its help.一般来说,这一切对我来说都很好,然后我可以使用kubectl来监控和管理我的集群,并在它的帮助下安装 Kubernetes Dashboard。 But one thing I don't like is that kops makes use of ELB.但我不喜欢的一件事是kops使用 ELB。 That was ok in the beginning and I used the URL provided by the load balancer to access the dashboard.一开始没问题,我使用负载均衡器提供的 URL 来访问仪表板。 Now I believe I can avoid using ELB to cut down my expenses on AWS.现在我相信我可以避免使用 ELB 来减少我在 AWS 上的开支。 Could you please tell me how I can use kops create cluster without any ELB but still be able to connect to my cluster and dashboard from my local machine?你能告诉我如何在没有任何 ELB 的情况下使用kops create cluster但仍然能够从我的本地机器连接到我的集群和仪表板吗?

The LB is needed to talk to the kube-apiserver which runs on the master.需要 LB 与在主服务器上运行的 kube-apiserver 通信。 You can bypass that by deleting the ELB from the AWS console and modifying your configs to talk directly to the public or private IP of your master.您可以通过从 AWS 控制台删除 ELB 并修改您的配置以直接与您的主节点的公共或私有 IP 通信来绕过它。 You might have to re-issue your certificates on the master so that you can talk to the new IP address.您可能必须在主服务器上重新颁发您的证书,以便您可以与新 IP 地址通信。 Kops creates an ELB because that's more a standard 'production' ready type of practice and also it's compatible if you have more than one master. Kops 创建了一个 ELB,因为这更像是一种标准的“生产”就绪类型的练习,而且如果您有多个大师,它也是兼容的。 In other words, it's still recommended to have that ELB.换句话说,仍然建议使用该 ELB。

As far as the dashboard, generally, the dashboard is exposed as a Kubernetes LoadBalancer Service in AWS that creates an ELB.就仪表板而言,通常,仪表板在 AWS 中公开为Kubernetes LoadBalancer 服务,用于创建 ELB。 You can simply delete the service and the load balancer should be deleted.您可以简单地删除服务,负载均衡器应该被删除。

$ kubectl delete svc <your-dashboard-svc>

Now if you want to avoid creating a load balancer on a service you just create a service with a ClusterIP or a NodePort .现在,如果您想避免在服务上创建负载均衡器,您只需创建一个带有 ClusterIP 或NodePort 的服务 Then you can access your service using something like kubectl proxy .然后你可以使用kubectl proxy类的东西访问你的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM