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授权
相关推荐
伊成3 小时前
细说Docker命令
docker·容器·eureka
java_logo3 小时前
vllm-openai Docker 部署手册
运维·人工智能·docker·ai·容器
阿里云大数据AI技术3 小时前
云栖实录|MaxCompute全新升级:AI时代的原生数据仓库
大数据·数据库·云原生
jiyuzzz4 小时前
Docker部署WordPress及相关配置
运维·docker·容器
风清再凯6 小时前
05-k8s网络
网络·容器·kubernetes
SunnyJim6 小时前
k8s NodePort 类型 Service 无法访问 plugin type=“flannel“ failed (add)
iptables·kubernetes·metrics·flannel·cni
西柚小萌新7 小时前
【Bug:docker】--Docker国内镜像源加载失败
docker·容器·bug
xiaogg36788 小时前
阿里云k8s部署微服务yaml和Dockerfile文件脚本
阿里云·微服务·kubernetes
爱宇阳8 小时前
GitLab Docker Compose 迁移教程
docker·容器·gitlab
●VON10 小时前
重生之我在大学自学鸿蒙开发第五天-《实战篇》
学习·华为·云原生·harmonyos·鸿蒙