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授权
相关推荐
Warren9814 分钟前
datagrip新建oracle连接教程
数据库·windows·云原生·oracle·容器·kubernetes·django
ascarl20101 小时前
准确--Kubernetes 修改 NodePort 端口范围操作文档
云原生·容器·kubernetes
何包蛋H1 小时前
Docker Maven 插件深度配置指南:Spotify vs Fabric8
docker·容器·maven
从零开始学习人工智能1 小时前
解决Docker容器无法访问宿主机IP和端口的全维度实践指南
tcp/ip·docker·容器
运维技术小记1 小时前
以Jellyfin为例,给群晖NAS容器里的应用升级
容器
隔壁阿布都2 小时前
Docker 安装 Redis
redis·docker·容器
少陽君2 小时前
Kubernetes Debug 专用镜像实践指南
云原生·容器·kubernetes
一过菜只因2 小时前
Docker入门
运维·docker·容器
weixin_46683 小时前
K8S-RBAC2
docker·容器·kubernetes
木风小助理4 小时前
云原生热点聚焦:OpenTofu 1.11.0 发布与关键工具更新
云原生