简体   繁体   中英

Kubernetes - Expose Website using nginx-ingress

I have a website running inside a kubernetes cluster. I can access it localy, but want to make it available over the internet. (I have a registered domain), but the external IP keeps pending

I worked with this instruction: 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.

EXTERNAL-IP is expected to be pending in a non cloud environment such as minikube. You should be able to access the application using curl www.carina.bernrieder.de

Here is guide on using nginx ingress to expose an application on minikube

As @Arghya Sadhu mentioned, in local environment it is the expected behaviour. 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". 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.

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.

But let's start from the beginning. You didn't mention in your question anything about your external IP or domain configuration. If you don't have an external static IP to which your domain has been redirected, it have no chances to work anyway.

As to this point, I won't fully agree:

You should be able to access the application using 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:

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. The IP address displayed within the ingress list will be the internal IP.

But keep in mind that both those IPs will be private IPs. 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. It will be still the IP in your local network assigned to your Minikube vm.

And as you said in your question you want to make it available over the 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. 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.

Minikube was designed mainly for playing locally with kubernetes and not for production environments. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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