I used the following nginx ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.5.1
name: ingress-nginx-controller
namespace: ingress-nginx
data:
allow-snippet-annotations: "true"
enable-real-ip: "true"
use-forwarded-headers: "true"
proxy-real-ip-cidr: "<pods_cidr>,<services_cidr>,<load_balance_ip>/32"
use-proxy-protocol: "false"
And added the statement externalTrafficPolicy: Local
on nginx Service that assign the load balance:
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.5.1
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
externalTrafficPolicy: Local
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- appProtocol: https
name: https
port: 443
protocol: TCP
targetPort: https
selector:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
type: LoadBalancer
loadBalancerIP: <load_balance_ip>
Then, I also configured ip-masq-agent with the follow ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: ip-masq-agent
namespace: kube-system
data:
config: |
nonMasqueradeCIDRs:
- <load_balance_ip>/32
- <pods_cidr>
- <services_cidr>
masqLinkLocal: false
resyncInterval: 30s
So, I deleted the DaemonSet ip-masq-agent and gke automatic recreated it.
After that, I got my gke cluster working as expected. And used with success nginx.ingress.kubernetes.io/whitelist-source-range
on Ingress.
You can find more information about ip-masq-agent on gke accessing https://cloud.google.com/kubernetes-engine/docs/how-to/ip-masquerade-agent