简体   繁体   English

Kubernetes - 使用 nginx-ingress 公开网站

[英]Kubernetes - Expose Website using nginx-ingress

I have a website running inside a kubernetes cluster.我有一个在 kubernetes 集群中运行的网站。 I can access it localy, but want to make it available over the internet.我可以在本地访问它,但希望通过 Internet 访问它。 (I have a registered domain), but the external IP keeps pending (我有注册域名),但是外部IP一直挂着

I worked with this instruction: https://dev.to/peterj/expose-a-kubernetes-service-on-your-own-custom-domain-52dd我使用了这个指令: https : //dev.to/peterj/expose-a-kubernetes-service-on-your-own-custom-domain-52dd

This is the code for the service and ingress这是服务和入口的代码

kind: Service
apiVersion: v1
metadata:
  name: app-service
spec:
  selector:
    app: website
  ports:
    - name: http
      protocol: TCP
      port: 3000
      targetPort: 3000

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: www.carina.bernrieder.de
      http:
        paths:
          - path: /
            backend:
              serviceName: app-service
              servicePort: 3000

So I'm using helm to install the nginx-controller, but after that Kubectl get all the external IP of the nginx controller keeps pending.所以我使用 helm 来安装 nginx-controller,但在那之后Kubectl 获取nginx 控制器的所有外部 IP 保持挂起。

EXTERNAL-IP is expected to be pending in a non cloud environment such as minikube. EXTERNAL-IP预计在 minikube 等非云环境中待定。 You should be able to access the application using curl www.carina.bernrieder.de您应该能够使用curl www.carina.bernrieder.de访问该应用程序

Here is guide on using nginx ingress to expose an application on minikube下面是指南上使用nginx的入口暴露于minikube的应用

As @Arghya Sadhu mentioned, in local environment it is the expected behaviour.正如@Arghya Sadhu 提到的,在当地环境中,这是预期的行为。 Maybe it will be easier to understand when you look a bit more deeply on how it works in cloud environments.当您更深入地了解它在云环境中的工作方式时,也许会更容易理解。 Without going into details, if you apply an Ingress resource on GKE , EKS or AKS , a few more things happen "under the hood".无需赘述,如果您在GKEEKSAKS上应用Ingress资源,则会在“幕后”发生更多事情。 A loadbalancer with an external IP is automatically created so your ingress can use it to forward external traffic to Pods deployed on your kubernetes cluster.与外部IP负载均衡器会自动创建这样的入口可以使用它的外部流量转发到Pods部署在kubernetes集群上。

Minikube doesn't have such capabilities as it cannot make any call to any API for additional infrastructure resources to be created, as it happens on cloud environments. Minikube没有这样的功能,因为它不能调用任何 API 来创建额外的基础设施资源,就像在云环境中发生的那样。

But let's start from the beginning.但让我们从头开始。 You didn't mention in your question anything about your external IP or domain configuration.您在问题中没有提及有关外部 IP 或域配置的任何内容。 If you don't have an external static IP to which your domain has been redirected, it have no chances to work anyway.如果您没有将域重定向到的外部静态 IP,则无论如何它都无法工作。

As to this point, I won't fully agree:关于这一点,我不会完全同意:

You should be able to access the application using curl www.carina.bernrieder.de您应该能够使用 curl www.carina.bernrieder.de访问该应用程序

Yes, you will be able to access it via your domain (actually via any domain that you don't even need to own) provided you add the following entry in your /etc/hosts file so DNS won't be used and it will be resolved based on this locally defined mapping:是的,只要您在/etc/hosts文件中添加以下条目,您就可以通过您的域(实际上是通过您甚至不需要拥有的任何域)访问它,这样 DNS 就不会被使用,它会根据这个本地定义的映射来解析:

172.17.0.15 www.carina.bernrieder.de

As you can read here :正如你可以在这里阅读:

Note: If you are running Minikube locally, use minikube ip to get the external IP.注意:如果您在本地运行 Minikube,请使用minikube ip获取外部 IP。 The IP address displayed within the ingress list will be the internal IP.入口列表中显示的 IP 地址将是内部 IP。

But keep in mind that both those IPs will be private IPs.但请记住,这两个 IP 都将是私有 IP。 The one, that is displayed within the ingress list will be internal cluster ip and the external one will be extarnal only from your Minikube cluster perspective.在入口列表中显示的一个将是内部集群 ip,而外部一个将仅从您的Minikube集群的角度来看是外部的。 It will be still the IP in your local network assigned to your Minikube vm.它仍然是分配给Minikube 虚拟机的本地网络中的 IP。

And as you said in your question you want to make it available over the Internet.正如您在问题中所说,您希望通过 Internet 提供它。 As you can see it has no chances to work without additional configuration.正如您所看到的,如果没有额外的配置,它就没有机会工作。

Another important thing.另一个重要的事情。 You didn't mention where your Minikube is actually installed, so I guess you set it up on your local computer and most probably you're behind NAT router.您没有提到Minikube的实际安装位​​置,所以我猜您是在本地计算机上设置的,而且很可能您在 NAT 路由器后面。 If this is your case, it won't be so easy to expose it on a public internet.如果这是您的情况,在公共互联网上公开它不会那么容易。 You will need to configure proper port forwarding rules on your router and of course you need a static IP or you need to configure dynamic DNS to be able to access your computer on the Internet via your dynami public IP.您需要在路由器上配置适当的端口转发规则,当然您需要一个静态 IP 或者您需要配置动态 DNS 以便能够通过您的动态公共 IP 访问 Internet 上的计算机。

Minikube was designed mainly for playing locally with kubernetes and not for production environments. Minikube主要是为在本地使用 kubernetes 而设计的,而不是用于生产环境。 Of course you can use it to run your small app, but then you may think about installing it on a VM in a cloud environment or some sort of VPS server.当然,您可以使用它来运行您的小型应用程序,但随后您可能会考虑将其安装在云环境中的 VM 或某种 VPS 服务器上。

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

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