I was able to reproduce this behavior.
1 If you will deploy Nginx Ingress
on GKE as per Nginx Docs it is working normally. Service
and Ingress
have the same IP.
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole cluster-admin \
--user $(gcloud config get-value account)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
configmap/ingress-nginx-controller created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
...
2 If you will Deploy Nginx Ingress Helm chart without any changes $ helm install ingress ingress-nginx/ingress-nginx
it will work as you described
Nginx ingress controller LoadBalancer service
will have one ExternalIP
and Ingress
will have another ExternalIP
.
$ kubectl get svc,ing
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/hello-v2-svc NodePort 10.8.2.119 <none> 8080:32492/TCP 58s
service/ingress-nginx-ingress-controller LoadBalancer 10.8.5.90 34.72.141.41 80:32280/TCP,443:31670/TCP 108s
service/ingress-nginx-ingress-default-backend ClusterIP 10.8.5.66 <none> 80/TCP 108s
service/kubernetes ClusterIP 10.8.0.1 <none> 443/TCP 169m
NAME HOSTS ADDRESS PORTS AGE
ingress.extensions/my-ingress * 34.66.191.241 80 58s
Regarding part if you should worry it depends. This will not charge you as GKE found only 1 LoadBalancer
which is Service LoadBalancer
. You can check that by:
$ gcloud compute url-maps list
Listed 0 items.
user@cloudshell:~ (project)$ gcloud compute forwarding-rules list
NAME REGION IP_ADDRESS IP_PROTOCOL TARGET
a655d3a06b55511ea89df42010a800fe us-central1 34.72.141.41 TCP us-central1/targetPools/a655d3a06b55511ea89df42010a800fe
3 If you want your Ingress
and Nginx LoadBalancer service
have the same ExternalIP
, you must set parameter controller.publishService.enabled
to true in helm command. This parameter can be found in Nginx Ingress docs.
controller.publishService.enabled if true, the controller will set the endpoint records on the ingress objects to reflect those on the service false
$ helm install ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true
After that you can deploy some YAMLs like:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-v2
spec:
selector:
matchLabels:
app: hello-v2
replicas: 1
template:
metadata:
labels:
app: hello-v2
spec:
containers:
- name: hellov2
image: "gcr.io/google-samples/hello-app:2.0"
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-v2-svc
labels:
app: hello-v2
spec:
type: NodePort
selector:
app: hello-v2
ports:
- port: 8080
targetPort: 8080
protocol: TCP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /hello-v2
backend:
serviceName: hello-v2-svc
servicePort: 8080
$ kubectl apply -f hello.yaml
deployment.apps/hello-v2 created
service/hello-v2-svc created
ingress.extensions/my-ingress created
$ kubectl get svc,ing
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/hello-v2-svc NodePort 10.8.3.51 <none> 8080:30572/TCP 19m
service/ingress-nginx-ingress-controller LoadBalancer 10.8.12.137 34.69.123.145 80:32720/TCP,443:31245/TCP 20m
service/ingress-nginx-ingress-default-backend ClusterIP 10.8.1.65 <none> 80/TCP 20m
service/kubernetes ClusterIP 10.8.0.1 <none> 443/TCP 163m
NAME HOSTS ADDRESS PORTS AGE
ingress.extensions/my-ingress * 34.69.123.145 80 19m
$ curl 34.69.123.145/hello-v2
Hello, world!
Version: 2.0.0
Hostname: hello-v2-7cf9b75bbf-2cdj5
EDIT
Lately Helm chart stable/nginx-ingress has been deprecated. Please use nginx-ingress/nginx-ingress
. Commands above, already changed.
Nginx
? What do you mean strange IP? Did you specify it somewhere in your YAMLs? Are you usingStaticIP
for thisLoadBalancer
? If notGKE
will createLoadBalancer
with "available"ExternalIP
address. Can you share your configuration YAMLs? In my opinion you should not be concerned about random external IP address if you did not specify it anywhere. – PjoterShelm install --name nginx-ingress stable/nginx-ingress --set controller.service.loadBalancerIP=<my_static_regional-IP>
. The only YAML I used was to define the ingress where I did not specify any IP. The "strange" one that came up was added by Google to the ingress yaml under status.loadBalancer.ingress.ip. However, if I view all load balancers in the console, only the NGINX one with my regional static IP shows. And the ingress definitely works how I expect it to. But it still shows that other IP. – apbassettcontroller.publishService.enabled
set totrue
to Nginx Service and Ingress have the same IP. Ive posted an answer with some clarification. – PjoterS