Apiserver的代理

T:在集群里发布一个deployment与service,通过apiserver去访问它

--proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
--proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key 
--requestheader-allowed-names=front-proxy-client 
--requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt 
--requestheader-extra-headers-prefix=X-Remote-Extra- 
--requestheader-group-headers=X-Remote-Group 
--requestheader-username-headers=X-Remote-User

猜测:apiserver可以作为代理转发到集群内service的后端服务,如果后端服务是HTTPS且需要一定的认证信息,那么apiserver就会利用到上面的参数

验证: 1、在k8s集群中创建一个Nginx容器,提供HTTPS服务,server.crt的域名为nginx,由front-proxy-ca.key与front-proxy-ca.crt签署。

2、在集群中创建一个Service名叫nginx,指向nginx容器

3、验证通过apiserver的地址能访问正常访问nginx服务

$ curl http://192.168.2.104:8080/api/v1/namespaces/default/services/https:nginx:8443/proxy/
...

验证2: 1、写一个python程序,提供http服务,该服务会返回请求头部中的参数;在主机上把这个python进程启起来 2、在集群中创建一个Service名叫python,不指定selector,手动创建名字为python的Endpoint,指向上面的python服务 3、访问apiserver的地址,携带头部参数,看返回;访问apiserver的地址,不携带头部参数,看返回

Last updated

Was this helpful?