You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ContainerIssues or pull requests relevant for Team 2: Container Infra and ToolingSCS-VP06cRelated to tender lot SCS-VP06cenhancementNew feature or request
As a container cluster users (DevOps team), I want to use externalTrafficPolicy: local behind a Load-Balancer not only for better performance, but to be able to see the Client IP address in e.g. the ingress controller.
In our current reference implementation, this is not the case, as the internal IP of the load-balancer (octavia) will be seen by the service, not the real client IP.
When we use the nginx-ingress, there should be a possibility to create a work around:
octavia can be told to use the proxy protocol to communicate the real client IP to a service
the service -- in this case nginx -- can be told to evaluate the special header
As this does need service specific configuration for most services (some might auto-detect and -evaluate a prozy protocol header), this is unfortunately not a generic solution. But still useful: As we offer to create an nginx-ingress along with cluster deployment, we can set everything in octavia and in ingress from one place to make it work. Further services that the user adds manually however, will not have client-IPs out-of-the-box unfortunately. Still useful ...
This user story is about researching whether this will work and how to make it work in our SCS reference implementation.
It is a reaction to the discussion in issue #227.
Prior discussion on using the proxy protocol in the nginx-ingress-octavia situation in our reference implementation: SovereignCloudStack/k8s-cluster-api-provider#184
Please read carefully. (Here's a TL;DR anyway:)
We know how to patch the nginx deployment files to enable the openstack annotation to use proxy headers.
We also can tell nginx to expect proxy headers, but this breaks internal connections, as noted by @flyersa
There may be a way to restrict proxy-protocol usage, but this needs research & validation.
I tested the behaviour of externalTrafficPolicy and the proxy protocol on the Hetzner Cloud so I am sharing notes about that. It seems that if we want to get real client IP, we need set provider(Hetzner) specific annotation on the LoadBalancer service, which sets proxy protocol on the load balancer.
Create and expose a small Nginx webserver that echoes back the client IP
$ k create deployment source-ip-app --image=registry.k8s.io/echoserver:1.4
$ k expose deployment source-ip-app --name=loadbalancer --port=80 --target-port=8080 --type=LoadBalancer
$ k get po -owide
NAME READY STATUS RESTARTS AGE IP NODE
source-ip-app-5c687d697b-fppck 1/1 Running 1 (177m ago) 20h 10.244.1.172 roman-cluster-md-0-29vqt
$ k get svc loadbalancer -owide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
loadbalancer LoadBalancer 10.103.111.206 10.0.0.6,2a01:4f9:c01d:433::1,65.109.42.56 80:31628/TCP 20h app=source-ip-app
Send a request to the LoadBalancer - externalTrafficPolicy: Cluster
Client address is IP of the node - because of SNAT:
$ curl 65.109.42.56
CLIENT VALUES:
client_address=65.109.204.179
...
$ k get node roman-cluster-md-0-29vqt -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP
roman-cluster-md-0-29vqt Ready <none> 21h v1.24.9 10.0.0.4 65.109.204.179
Send a request to the LoadBalancer - externalTrafficPolicy: Local
Client address is IP of the LoadBalancer - there is no SNAT:
# Hetzner CCM configures load balancer via annotations
$ k annotate svc loadbalancer 'load-balancer.hetzner.cloud/uses-proxyprotocol'=true
service/loadbalancer annotated
Nginx webserver needs to be modified to accept proxy protocol, otherwise we get 400 Bad Request:
$ k exec -it source-ip-app-5c687d697b-fppck -- bash
root@source-ip-app-5c687d697b-fppck:/# cat /etc/nginx/nginx.conf#...
http {
#...
server {
# add the proxy_protocol parameter to the listen directive to accept proxy protocol# $proxy_protocol_addr now represents client IP
listen 8080 default_server reuseport proxy_protocol;# you can change value of $remote_addr with RealIP module# 'http_realip_module' needs to be installed(not the case for this container)# specify IP address or the CIDR range of addresses of the TCP proxy or load balancer#set_real_ip_from 65.109.204.179; # node IP in case of externalTrafficPolicy: Cluster#set_real_ip_from 65.109.42.56; # loadbalancer IP in case of externalTrafficPolicy: Local
set_real_ip_from 0.0.0.0/0;# if you don't know IP#set_real_ip_from 10.0.0.0/16; # if your load balancer/node uses private IP# change IP with real_ip_header directive
real_ip_header proxy_protocol;#...
}
}
root@source-ip-app-5c687d697b-fppck:/# nginx -s reload
One problem we ran into was issue SovereignCloudStack/k8s-cluster-api-provider#184:
When you access the service internally, the requests don't come from the LB and nginx then rejects due to missing proxy protocol. Do you observe the same on Hetzner?
I observed the same on Hetzner. When the proxy protocol is turned on, I cannot access the service internally(e.g. from the pod).
So exactly the same behaviour, because the request doesn't go through the LB, so there is no proxy protocol at all.
I tried the workaround, which was mentioned by @flyersahere.
Hetzner has a specific annotation load-balancer.hetzner.cloud/hostname, which causes the hostname to be populated to the status.loadBalancer.ingress of the loadbalancer service instead of LB IP.
After adding a hostname, I am able to access lb service internally.
This all happens because kube-proxy adds an iptables rule for the loadbalancer external IP, causing traffic to bypass the LB.
It seems that mentioned "workaround" is based on the behaviour of AWS loadbalancer, which adds LB hostname instead of its IP
and therefore kube-proxy can't add it to the iptables and traffic goes through LB.
This behaviour was fixed in the upstream kubernetes project for the v1.20, but later it was reverted.
There is now opened issue which addresses the lb problem - milestone v1.28. The enhancement proposal is KEP-1860.
It seems that some providers adopt this hostname solution for this problem until the kubernetes project resolve that issue,
e.g. DO or linode.
Also in almost all other providers, it is possible to set some kind of hostname annotation.
I also investigated issue mentioned by @flyersa and
OpenStack Cloud Controller Manager is no exception. There is loadbalancer.openstack.org/hostname annotation, which can be used to explicitly set a hostname in the status of the load balancer service.
But there is also one unique option in the occm which I have not found anywhere else. It is called enable-ingress-hostname.
It is used only when there is annotation loadbalancer.openstack.org/proxy-protocol: "true". It adds dns suffix nip.io(it can be changed) to the load balancer IP address. So basically it creates hostname IPaddress.nip.io, returns it to the status of lb service and everything works.
I have found that it was adopted by kops and kubespray. Probably there are other projects.
I have also found a problem with this setup in external-dns project, but I don't know if it is fixed or whether it should interest us at all because we don't have external-dns in our stack.
Can we adopt this solution? We can probably set this occm setting when nginx-ingress is deployed as a load balancer with proxy protocol on. Then the service should be accessible externally as well as internally.
During tests with Occm LoadBalancer setting enable-ingress-hostname, I found one issue in 1.25 version.
When we install e.g. k8s version 1.25.4 we match occm version 1.25.3, but manifest which we curl from occm repo contains "only" images with tag 1.25.0.
Then when I tried to test the setting mentioned above, I hit a bug with occm 1.25.0. It was fixed in 1.25.2 but unfortunately, the image used in the manifest is 1.25.0 so the fix is not applied. So I created this PR which ensures the correct version is used in the manifest.
Apart from that problem, I tested it so it has the expected behaviour. I will do further tests and prepare PR.
$ k get deploy,svc,ing source-ip-app
NAME READY UP-TO-DATE AVAILABLE
deployment.apps/source-ip-app 1/1 1 1
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
service/source-ip-app ClusterIP 10.102.165.90 <none> 80/TCP
NAME CLASS HOSTS ADDRESS PORTS
ingress.networking.k8s.io/source-ip-app nginx * 213.131.230.192 80
$ curl 213.131.230.192
curl: (52) Empty reply from server
$ wget 213.131.230.192
Connecting to 213.131.230.192 (213.131.230.192:80)
wget: error getting response
It doesn't work from within the cluster.
Internal traffic does work
Use same procedure as above but now set enable-ingress-hostname=true in the [LoadBalancer] section of cloud.conf and notice differences:
$ k -n ingress-nginx get svc ingress-nginx-controller
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
ingress-nginx-controller LoadBalancer 10.109.235.18 213.131.230.192.nip.io 80:31729/TCP,443:30709/TCP
$ k get ing source-ip-app
NAME CLASS HOSTS ADDRESS PORTS
source-ip-app nginx * 213.131.230.192.nip.io 80
I prepared this PR which adds enable-ingress-hostname=true to the occm config. This config option is used only when the annotation loadbalancer.openstack.org/proxy-protocol: "true", so for now, this setting is hardcoded, but after discussion, it can be set during the creation of cluster based on some variable.
After research and tests, it seems to work as expected.
Also for k8s version 1.25 to work the PR has to be merged first as mentioned in this comment.
ContainerIssues or pull requests relevant for Team 2: Container Infra and ToolingSCS-VP06cRelated to tender lot SCS-VP06cenhancementNew feature or request
Activity
garloff commentedon Jan 17, 2023
Prior discussion on using the proxy protocol in the nginx-ingress-octavia situation in our reference implementation:
SovereignCloudStack/k8s-cluster-api-provider#184
Please read carefully. (Here's a TL;DR anyway:)
garloff commentedon Jan 17, 2023
Your insight is very welcome, @batistein , @janiskemper , @joshmue , @chess-knight , @ajfriesen, @horazont .
chess-knight commentedon Jan 18, 2023
I tested the behaviour of
externalTrafficPolicyand the proxy protocol on the Hetzner Cloud so I am sharing notes about that. It seems that if we want to get real client IP, we need set provider(Hetzner) specific annotation on the LoadBalancer service, which sets proxy protocol on the load balancer.Preserving the client source IP
docs
tutorial
Create and expose a small Nginx webserver that echoes back the client IP
Send a request to the LoadBalancer -
externalTrafficPolicy: ClusterClient address is
IP of the node- because of SNAT:Send a request to the LoadBalancer -
externalTrafficPolicy: LocalClient address is
IP of the LoadBalancer- there is no SNAT:$ k patch svc loadbalancer -p '{"spec":{"externalTrafficPolicy":"Local"}}' service/loadbalancer patched $ curl 65.109.42.56 CLIENT VALUES: client_address=65.109.42.56 ...How to get "real" client IP
Use proxy protocol on the LoadBalancer:
Nginx webserver needs to be modified to accept proxy protocol, otherwise we get 400 Bad Request:
Client address is now "real" client IP:
garloff commentedon Jan 18, 2023
Thanks, Roman!
On SCS clouds, the corresponding setting is an OpenStack-specific annotation:
loadbalancer.openstack.org/proxy-protocol: "true"and then patch the nginx charts to enable the proxy protocol.
We use kustomize as a robust method to patch yamls, see https://github.com/SovereignCloudStack/k8s-cluster-api-provider/tree/main/terraform/files/kubernetes-manifests.d/nginx-ingress/nginx-proxy
One problem we ran into was issue SovereignCloudStack/k8s-cluster-api-provider#184:
When you access the service internally, the requests don't come from the LB and nginx then rejects due to missing proxy protocol. Do you observe the same on Hetzner?
chess-knight commentedon Jan 19, 2023
I observed the same on Hetzner. When the proxy protocol is turned on, I cannot access the service internally(e.g. from the pod).
So exactly the same behaviour, because the request doesn't go through the LB, so there is no proxy protocol at all.
I tried the workaround, which was mentioned by @flyersa here.
Hetzner has a specific annotation
load-balancer.hetzner.cloud/hostname, which causes the hostname to be populated to the status.loadBalancer.ingress of the loadbalancer service instead of LB IP.After adding a hostname, I am able to access lb service internally.
This all happens because kube-proxy adds an iptables rule for the loadbalancer external IP, causing traffic to bypass the LB.
It seems that mentioned "workaround" is based on the behaviour of AWS loadbalancer, which adds LB hostname instead of its IP
and therefore kube-proxy can't add it to the iptables and traffic goes through LB.
This behaviour was fixed in the upstream kubernetes project for the v1.20, but later it was reverted.
There is now opened issue which addresses the lb problem - milestone v1.28. The enhancement proposal is KEP-1860.
It seems that some providers adopt this hostname solution for this problem until the kubernetes project resolve that issue,
e.g. DO or linode.
Also in almost all other providers, it is possible to set some kind of hostname annotation.
I also investigated issue mentioned by @flyersa and
OpenStack Cloud Controller Manager is no exception. There is
loadbalancer.openstack.org/hostnameannotation, which can be used to explicitly set a hostname in the status of the load balancer service.But there is also one unique option in the occm which I have not found anywhere else. It is called
enable-ingress-hostname.It is used only when there is annotation
loadbalancer.openstack.org/proxy-protocol: "true". It adds dns suffix nip.io(it can be changed) to the load balancer IP address. So basically it creates hostname IPaddress.nip.io, returns it to the status of lb service and everything works.I have found that it was adopted by kops and kubespray. Probably there are other projects.
I have also found a problem with this setup in external-dns project, but I don't know if it is fixed or whether it should interest us at all because we don't have external-dns in our stack.
Can we adopt this solution? We can probably set this occm setting when nginx-ingress is deployed as a load balancer with proxy protocol on. Then the service should be accessible externally as well as internally.
garloff commentedon Jan 23, 2023
The hostname approach will be further investigated and tested and looks like a valid option if it all works.
chess-knight commentedon Jan 30, 2023
During tests with Occm LoadBalancer setting enable-ingress-hostname, I found one issue in 1.25 version.
When we install e.g. k8s version 1.25.4 we match occm version 1.25.3, but manifest which we curl from occm repo contains "only" images with tag 1.25.0.
Then when I tried to test the setting mentioned above, I hit a bug with occm 1.25.0. It was fixed in 1.25.2 but unfortunately, the image used in the manifest is 1.25.0 so the fix is not applied. So I created this PR which ensures the correct version is used in the manifest.
Apart from that problem, I tested it so it has the expected behaviour. I will do further tests and prepare PR.
Modify LB IP with dns suffix when the proxy protocol is used
chess-knight commentedon Jan 31, 2023
Internal traffic doesn't work
Create a cluster with
NGINX_INGRESS_PROXY: truein the clusterctl.yaml:Create an example application and expose it via ingress:
Send a request to the load balancer IP:
Internal traffic does work
Use same procedure as above but now set
enable-ingress-hostname=truein the [LoadBalancer] section of cloud.conf and notice differences:$ k -n ingress-nginx get svc ingress-nginx-controller NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) ingress-nginx-controller LoadBalancer 10.109.235.18 213.131.230.192.nip.io 80:31729/TCP,443:30709/TCP $ k get ing source-ip-app NAME CLASS HOSTS ADDRESS PORTS source-ip-app nginx * 213.131.230.192.nip.io 80The IP address is suffixed with
nip.io.Send a request to the load balancer IP:
Conclusion
I prepared this PR which adds
enable-ingress-hostname=trueto the occm config. This config option is used only when the annotationloadbalancer.openstack.org/proxy-protocol: "true", so for now, this setting is hardcoded, but after discussion, it can be set during the creation of cluster based on some variable.After research and tests, it seems to work as expected.
Also for k8s version 1.25 to work the PR has to be merged first as mentioned in this comment.
Modify LB IP with dns suffix when the proxy protocol is used (#323)
jschoone commentedon Apr 3, 2023
As discussed in container meeting CW14 the research has been done
Modify LB IP with dns suffix when the proxy protocol is used (#323)