HCIE-kubernetes(k8s)-Authentication身份验证

1、远程登录

1、kubeconfig方式

在master上都是以kubeconfig方式登录的,并不是说有一个文件叫kubeconfig。

默认使用的配置文件是~/.kube/config 这个配置文件,而这个配置文件是通过这个文件/etc/kubernetes/admin.conf

bash 复制代码
如果在node上执行命令,也需要配置该文件,否则报错如下:
[root@node1 ~]# kubectl get node
E1103 15:42:46.225278  129198 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E1103 15:42:46.226197  129198 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E1103 15:42:46.228511  129198 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E1103 15:42:46.230491  129198 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
E1103 15:42:46.232909  129198 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
The connection to the server localhost:8080 was refused - did you specify the right host or port?
bash 复制代码
可以在master拷贝一份/etc/kubernetes/admin.conf到node1
[root@master ~]# cd /etc/kubernetes
[root@master kubernetes]# scp admin.conf 10.1.1.201:~
在node1上执行命令的时候,直接指定该文件运行。
[root@node1 ~]# kubectl get node --kubeconfig=admin.conf
NAME     STATUS   ROLES           AGE   VERSION
master   Ready    control-plane   8d    v1.27.0
node1    Ready    <none>          8d    v1.27.0
node2    Ready    <none>          8d    v1.27.0
如果不想指定配置文件,可以直接配置环境变量。
[root@node1 ~]# echo 'export KUBECONFIG=admin.conf' >> /etc/profile
[root@node1 ~]# source /etc/profile
[root@node1 ~]# kubectl get node
NAME     STATUS   ROLES           AGE   VERSION
master   Ready    control-plane   8d    v1.27.0
node1    Ready    <none>          8d    v1.27.0
node2    Ready    <none>          8d    v1.27.0
这样就不需要指定配置文件了。
注意:该admin.conf文件是直接从master上拷贝过来的,所以默认具备admin管理员最大的权限的。
生产环境不建议这样操作,因为权限过大,无法保证安全性。
bash 复制代码
例如单独创建用户tom授权
相关推荐
CNRio1 天前
第六章-DockerCompose:多容器应用的‘指挥家‘
容器
summer_west_fish1 天前
K8S Advance: 集群 IP 地址管理指南
tcp/ip·容器·kubernetes
b***62951 天前
使用Docker部署postgresql
docker·postgresql·容器
Liangomy1 天前
FAST-Calib 激光雷达与相机联合标定教程 (Docker版)
数码相机·docker·容器
7***n751 天前
后端在微服务中的Traefik
微服务·云原生·架构
de之梦-御风1 天前
【远程控制】RustDesk 自建服务端完整方案(Docker + Windows 客户端)
windows·docker·容器
de之梦-御风1 天前
【远程控制】开箱即用的 RustDesk 自建服务端完整 Docker Compose 模板
运维·docker·容器
悟空码字1 天前
Kubernetes实战:你的分布式系统“保姆”养成记
java·后端·kubernetes
openFuyao1 天前
openFuyao两大核心项目获得GitCode G-Star认证 社区生态迈向成熟
人工智能·云原生·开源软件
努力也学不会java1 天前
【docker】Docker Register(镜像仓库)
运维·人工智能·机器学习·docker·容器