Bootstrap

容器 & 服务:Kubernetes API Server访问问题

系列文章:

一 回顾

回到容器系列,前面我们在本地环境搭建了Kubernetes集群,但访问api server时遇到一些问题,还没有处理完毕,本篇尝试解决。

二 API Server访问报错

本地接口访问地址:https://localhost:6443/, 接口返回的数据如下:

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
  "reason": "Forbidden",
  "details": {
    
  },
  "code": 403
}

如上所示,status 为 Failure,说明访问失败;错误信息为:forbidden: User \"system:anonymous\" cannot get path \"/\"。可见是权限相关问题,code为403。

通过相关资料查询,是访问证书的问题。通过使用client-certificate-data和client-key-data生成一个p12文件,添加证书,可以解决。

三 证书生成

四 raw.githubusercontent.com无法访问问题

在github代码下载,或本文中安装dashboard需要访问github上的文件时,会出现GitHub网页githubusercontent地址无法访问的问题,这会直接阻塞我们的操作流程。错误信息如下:

curl -o kubernetes-dashboard.yaml  https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

这个问题的解决方案,我们可以参考文章:。重点在于hosts文件配置,在/etc/hosts中,增加一行 199.232.96.133    raw.githubusercontent.com。注:地址可能发生变化,如果发现无效,那么参考 获取最新版的站点地址。

hosts配置完成后,先ping :

访问正常,再次尝试下载配置文件:

k8s-for-docker-desktop % curl -o kubernetes-dashboard.yaml  https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    14  100    14    0     0     11      0  0:00:01  0:00:01 --:--:--    11

下载成功。