Kubernetes – kubectl proxy 让外部网络访问K8S api-service

查看K8s集群信息

[root@k8s-master ~]# kubectl cluster-info
Kubernetes master is running at https://192.168.1.8:6443
KubeDNS is running at https://192.168.1.8:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

使用kubectl proxy命令就可以使API server监听在本地的8001端口上:

$ kubectl proxy
Starting to serve on 127.0.0.1:8001

如果想通过其它主机指定端口访问就需要指定监听的地址:

$ kubectl proxy --address=0.0.0.0 --port=8009
Starting to serve on [::]:8009

此时通过curl访问会出现未认证的提示:

$ curl -X GET -L http://k8s-master:8009/
<h3>Unauthorized</h3>

设置API server接收所有主机的请求:

$ kubectl proxy --address='0.0.0.0' --accept-hosts='^*$' --port=8009
Starting to serve on [::]:8009

访问正常:

$ curl -X GET -L http://k8s-master:8009/
{
  "paths": [
    "/api",
    "/api/v1",
    ...
  ]
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/23/kubernetes-kubectl-proxy-allows-external-networks-to-access-k8s-api-service/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Kubernetes – kubectl proxy 让外部网络访问K8S api-service
查看K8s集群信息 [root@k8s-master ~]# kubectl cluster-info Kubernetes master is running at https://192.168.1.8:6443 KubeDNS is running at https://192……
<<上一篇
下一篇>>
文章目录
关闭
目 录