Kubernetes集群Node管理
k8s集群如果由大量节点组成,可将节点打上对应的标签,然后通过标签进行筛选及查看,更好的进行资源对象的相关选择与匹配。加上--overwrite=true覆盖原标签的value进行修改操作。使用kubeadm安装,在node节点上管理时会报如下错误。标签为shenzhen,A机房,测试环境,oa业务。3, 在worker node节点验证。1, 在node节点的用户家目录创建。使用key加一个减号
目录
一、查看集群信息
[root@k8s-master1 ~]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.10.100:6443
CoreDNS is running at https://192.168.10.100:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
二、查看节点信息
2.1 查看集群节点信息
[root@k8s-master1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master1 Ready <none> 2d20h v1.21.10
k8s-master2 Ready <none> 2d20h v1.21.10
k8s-master3 Ready <none> 2d20h v1.21.10
k8s-worker1 Ready <none> 2d20h v1.21.10
2.2 查看集群节点详细信息
[root@k8s-master1 ~]# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master1 Ready <none> 2d20h v1.21.10 192.168.10.12 <none> CentOS Linux 7 (Core) 5.17.0-1.el7.elrepo.x86_64 containerd://1.6.1
2.3 查看节点描述详细信息
[root@k8s-master1 ~]# kubectl describe node k8s-master1
三、worker node节点管理集群
使用kubeadm安装,在node节点上管理时会报如下错误
[root@k8s-worker1 ~]# kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?
其实只要把master上的管理文件/etc/kubernetes/admin.conf
拷贝到node节点的$HOME/.kube/config
就可以让node节点也可以实现kubectl命令管理
1, 在node节点的用户家目录创建.kube
目录
[root@k8s-worker1 ~]# mkdir /root/.kube
2.在master节点做如下操作
scp /etc/kubernetes/admin.conf node1:/root/.kube/config
3, 在worker node节点验证
[root@k8s-worker1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master1 Ready <none> 2d20h v1.21.10
四、节点标签(label)
-
k8s集群如果由大量节点组成,可将节点打上对应的标签,然后通过标签进行筛选及查看,更好的进行资源对象的相关选择与匹配
-
4.1 查看节点标签信息
- [root@k8s-master1 ~]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master1 Ready <none> 2d20h v1.21.10 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master1,kubernetes.io/os=linux
k8s-master2 Ready <none> 2d20h v1.21.10 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master2,kubernetes.io/os=linux
4.2 设置节点标签信息
4.2.1 设置节点标签
为节点k8s-worker1
打一个region=shenzhen
的标签
[root@k8s-master1 ~]# kubectl label node k8s-worker1 region=shenzhen
node/k8s-worker1 labeled
4.2.2 查看所有节点标签
[root@k8s-master1 ~]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master1 Ready <none> 2d21h v1.21.10 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master1,kubernetes.io/os=linux
4.2.3 查看所有节点带region的标签
[root@k8s-master1 ~]# kubectl get nodes -L region
NAME STATUS ROLES AGE VERSION REGION
k8s-master1 Ready <none> 2d21h v1.21.10
k8s-master2 Ready <none> 2d21h v1.21.10
k8s-master3 Ready <none> 2d21h v1.21.10
k8s-worker1 Ready <none> 2d21h v1.21.10 shenzhen
4.3 多维度标签
4.3.1 设置多维度标签
如把k8s-master3
标签为shenzhen,A机房,测试环境,oa业务
[root@k8s-master1 ~]# kubectl label node k8s-master3 zone=A env=test bussiness=oa
node/k8s-master3 labeled
[root@k8s-master1 ~]# kubectl get nodes k8s-master3 --show-labels
4.3.2 标签的修改
[root@k8s-master1 ~]# kubectl label node k8s-master3 bussiness=ad --overwrite=true
node/k8s-master3 labeled
加上--overwrite=true覆盖原标签的value进行修改操作
4.3.3 标签的删除
使用key加一个减号的写法来取消标签
[root@k8s-master1 ~]# kubectl label node k8s-worker1 region-
node/k8s-worker1 labeled
4.3.4 标签选择器
标签选择器主要有2类:
-
等值关系: =, !=
-
集合关系: KEY in {VALUE1, VALUE2......}
[root@k8s-master1 ~]# kubectl label node k8s-master2 env=test1
node/k8s-master2 labeled
[root@k8s-master1 ~]# kubectl label node k8s-master3 env=test2
node/k8s-master3 labeled
[root@k8s-master1 ~]# kubectl get node -l "env in(test1,test2)"
NAME STATUS ROLES AGE VERSION
k8s-master2 Ready <none> 2d21h v1.21.10
k8s-master3 Ready <none> 2d21h v1.21.10
更多推荐
所有评论(0)