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授权
相关推荐
江畔何人初10 小时前
pod的定义以及创建过程
linux·运维·云原生
等什么君!11 小时前
docker -数据卷技术
运维·docker·容器
花酒锄作田12 小时前
Debian 13基于kubeadm和containerd部署单节点kubernetes
kubernetes·containerd·cilium
上天_去_做颗惺星 EVE_BLUE12 小时前
Docker高效使用指南:从基础到实战模板
开发语言·ubuntu·docker·容器·mac·虚拟环境
Gary董13 小时前
高并发的微服务架构如何设计
微服务·云原生·架构
东哥爱编程13 小时前
使用Runpod进行gpu serverless推理
云原生·serverless
好好沉淀14 小时前
Docker开发笔记(详解)
运维·docker·容器
Ankie Wan15 小时前
cgroup(Control Group)是 Linux 内核提供的一种机制,用来“控制、限制、隔离、统计”进程对系统资源的使用。
linux·容器·cgroup·lxc
lcx_defender16 小时前
【Docker】Docker部署运行nacos
运维·docker·容器
啦啦啦小石头17 小时前
docker添加用户权限不使用sudo
运维·docker·容器