简体   繁体   English

如何将新的子域添加到现有的 kubernetes 集群

[英]How to add new subdomain to existing kubernetes cluster

totally beginner with kubernetes and i believe this should be a simple question for any kubernetes expert完全是 Kubernetes 的初学者,我相信这对于任何 Kubernetes 专家来说都是一个简单的问题

to put a long story short: i have inherited a kubernetes cluster after my CTO quit his job.长话短说:在我的 CTO 辞职后,我继承了一个 Kubernetes 集群。 My goal is to make a new app accessible at a new subdomain for our company我的目标是让我们公司的新子域可以访问新应用程序

context:语境:

  1. the app in question has a service definition and deployment definition that have been applied to the cluster (ex: kubectl apply -f new-service.yaml)有问题的应用程序具有已应用于集群的服务定义和部署定义(例如:kubectl apply -f new-service.yaml)
  2. the pod is running the app as far as i can tell (shows up in my kubectl get pods output as ready and running)据我所知,pod 正在运行应用程序(在我的 kubectl get pods 输出中显示为准备就绪并正在运行)
  3. and i can ping that pod from other pods in the cluster我可以从集群中的其他 pod ping 那个 pod

my problem:我的问题:

i do not know how to make the ingress router "work"... i have updated my ingress yaml configuration by adding the host and service name, and I have used the command kubectl apply -f ingress.yaml to update the ingress configuration.我不知道如何使入口路由器“工作”......我通过添加主机和服务名称更新了入口 yaml 配置,并且我使用了命令 kubectl apply -f ingress.yaml 来更新入口配置。 but the new host is unreachable.但新主机无法访问。 I have even gone so far as to add a new host (a subdomain of our company) with a serviceName of an already functioning service that is accessible on a different subdomain -- hoping that i would see the already working app on my new subdomain.我什至添加了一个新主机(我们公司的一个子域),它的 serviceName 是一个已经运行的服务,可以在不同的子域上访问——希望我能在我的新子域上看到已经在工作的应用程序。 however, this new subdomain does not direct me to the app, chrome gives me the following output:但是,这个新的子域并没有将我引导到应用程序,chrome 给了我以下输出:

server IP address could not be found.

ERR_NAME_NOT_RESOLVED

is there something i'm missing here?我在这里缺少什么吗? shouldn't i be able to add a new host to the bottom of my ingress yaml and give it a serviceName of an already working service?我不应该能够在我的入口 yaml 的底部添加一个新主机并给它一个已经工作的服务的 serviceName 吗? and then be able to access that already running app from a different subdomain?然后能够从不同的子域访问已经运行的应用程序?

any help at all would be so greatly appreciated -- this is the last step for me in a long journey!任何帮助都将非常感激 - 这是我漫长旅程的最后一步! here is a snip of what i added to the ingress yaml -- this matches the other entry exactly except the hostname is www3 and not www这是我添加到入口 yaml 的内容的片段——这与另一个条目完全匹配,除了主机名是 www3 而不是 www

- host: www3.changed-for-privacy.com
      http:
        paths:
          - path: /*
            backend:
              serviceName: changed-for-privacy-www
              servicePort: 80

I believe what you are doing on the side of Kubernetes is perfectly okay.我相信你在 Kubernetes 方面所做的一切都很好。 A request for a certain domain, if/when received in your Ingress is correctly being routed to the backend service.如果/当在您的 Ingress 中收到时,对某个域的请求被正确路由到后端服务。

What is noteworthy is the error you show from Chrome .值得注意的是您从Chrome显示的错误。 This means the address resolution problem is on your client side, not the cluster.这意味着地址解析问题出在您的客户端,而不是集群。 You need to make sure that you setup local DNS resolution on your laptop so that your www3.changed-for-privacy.com will resolve to a knownIPAddress .您需要确保在笔记本电脑上设置本地 DNS 解析,以便您的www3.changed-for-privacy.com将解析为knownIPAddress For example, if you've set your Ingress externalIP to 192.168.10.10 .例如,如果您已将Ingress externalIP 设置为192.168.10.10 Then you have to add an entry to your /etc/hosts/ file (if you're on linux) as follows:然后你必须在/etc/hosts/文件中添加一个条目(如果你在 linux 上),如下所示:

www3.changed-for-privacy.com 192.168.10.10

This will ensure that requests for your domain from the browser land on the Ingress external IP (which should be routable of course) and you might find out that your cluster is working fine!这将确保来自浏览器对您的域的请求落在Ingress外部 IP(当然应该是可路由的)上,并且您可能会发现您的集群工作正常!

As a more permanent solution, you will of course require that your application domain is registered, so that a public DNS record for it will exist, which will map to the public externalIP of your Ingress object and you will not have this problem.作为一个更持久的解决方案,您当然会要求您的应用程序域已注册,以便存在它的公共 DNS 记录,该记录将映射到您的Ingress对象的公共externalIP IP,您将不会遇到此问题。

Question has been resolved!问题已解决!

Fortunately this had nothing to do with kubernetes!幸运的是,这与 Kubernetes 无关! My domain is pointing to cloudflare nameservers... which I did not realize at the time.我的域指向 cloudflare 域名服务器……当时我没有意识到。 I assumed the domain was pointing to AWS nameservers.我假设该域指向 AWS 名称服务器。 I was looking in Route 53 in AWS and was dumbfounded to see that adding a new CNAME record caused DNS name resolution errors when trying to hit the domain in the browser.我在 AWS 的 Route 53 中查看,当我尝试在浏览器中访问域时,我惊讶地发现添加新的 CNAME 记录会导致 DNS 名称解析错误。

Adding the new A records in cloudflare solved my problem在 cloudflare 中添加新的 A 记录解决了我的问题

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

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