Flow:
kubernetes cluster with api server (https://192.168.0.10:6443) <-> load balancer (10.10.0.2) <-> laptop.
Idea:
From my laptop I would like to run kubectl pointing to load balancer where reveres proxy will redirect me to api server.
Steps:
- I changed server ip in kubeconfig (on my laptop) file to LB's IP:
was https://192.168.0.10:6443 is http://10.10.0.2:8080/
- I configured nginx like that:
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
location / {
proxy_pass https://192.168.0.10:6443;
}
}
Now running for example kubectl get nodes I expected to get list of nodes but it won't work:
error: You must be logged in to the server (Unauthorized)
$ curl http://10.10.0.2:8080/
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "Unauthorized",
"reason": "Unauthorized",
"code": 401
If I add to nginx config:
ssl on;
ssl_certificate /root/certs/admin-k-master-1.pem;
ssl_certificate_key /root/certs/admin-k-master-1-key.pem;
and change in kubeconfig file server IP to https://10.10.0.2:8080/
$ kubect get nodes
Unable to connect to the server: x509: certificate is valid for 192.168.0.10 not 10.10.0.2
There is similar topic but it's not related to kubectl.
How can I achieve that? or what I am doing wrong.