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授权
相关推荐
scugxl12 小时前
centos7 docker离线安装
运维·docker·容器
LQ深蹲不写BUG14 小时前
微服务的保护方式以及Sentinel详解
微服务·云原生·架构
Serverless社区16 小时前
重塑云上 AI 应用“运行时”,函数计算进化之路
阿里云·云原生·serverless
落日漫游18 小时前
K8s资源管理:高效管控CPU与内存
java·开发语言·kubernetes
deepwater_zone19 小时前
现代云原生数据平台
云原生
ZLRRLZ20 小时前
【Docker】Docker基础
运维·docker·容器
ggaofeng21 小时前
k8s网络原理
网络·容器·kubernetes
老实巴交的麻匪1 天前
(六)学习、实践、理解 CI/CD 与 DevOps:GitHub Actions 工作流实践
后端·云原生·自动化运维
向上的车轮1 天前
云原生的12个要素是什么?
云原生
只因在人海中多看了你一眼1 天前
B.50.10.10-微服务与电商应用
微服务·云原生·架构