Global static IP name on NGINX Ingress

2020-06-08 20:36发布

问题:

I'm having difficulties getting my Ingress controller running on Google Container Engine. I want to use an NGINX Ingress Controller with Basic Auth and use a reserved global static ip name (this can be made in the External IP addresses section in the Google Cloud Admin interface). When I use the gce class everything works fine except for the Basic Auth (which I think is not supported on the gce class), anenter code hered when I try to use the nginx class the Ingress Controller launches but the IP address that I reserved in the Google Cloud Admin interface will not be attached to the Ingress Controller. Does anyone know how to get this working? Here is my config file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: webserver
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "myreservedipname"
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/auth-type: basic
    ingress.kubernetes.io/auth-realm: "Auth required"
    ingress.kubernetes.io/auth-secret: htpasswd
spec:
  tls:
    - secretName: tls
  backend:
    serviceName: webserver
    servicePort: 80

回答1:

I found a solution with helm.

helm install --name nginx-ingress stable/nginx-ingress \
      --set controller.service.loadBalancerIP=<YOUR_EXTERNAL_IP>

You should use the external-ip and not the name you gave with gcloud.

Also, in my case I also added --set rbac.create=true for permissions.



回答2:

External IP address can be attached to the Load Balancer which you can point to your Ingress controller.

One major remark - the External IP address should be reserved in the same region as the Kubernetes cluster.

To do it, you just need to deploy your Nginx-ingress service with type: LoadBalancer and set ExternalIP value, like this:

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
spec:
  loadBalancerIP: <YOUR_EXTERNAL_IP>
  type: LoadBalancer
  selector:
    app: ingress-nginx
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: https

After deployment, Kubernetes will create a new Load Balancer with desired static IP which will be an entry-point for your Ingress.

@silgon, as I see, you already tried to do it, but without a positive result. But, it should work. If not - check the region of IP address and configuration once again.



回答3:

Here's an example that I know works, could be an issue around your syntax:

kind: Ingress
metadata:
name: nginx
spec:
rules:
- host: nginx.192.168.99.100.nip.io
http:
paths:
- backend:
serviceName: nginx
servicePort: 80