一 实验环境
服务器版本 | docker软件版本 | Kubernetes(k8s)集群版本 | CPU架构 |
---|---|---|---|
Ubuntu 20.04.4 LTS 20.04 | Docker version 20.10.13 | v1.23.3+k3s1 | 模拟 |
服务器 | 操作系统版本 | CPU架构 | 进程 | 功能描述 |
---|---|---|---|---|
master01 | Ubuntu 20.04.4 LTS 20.04 | 模拟 | docker,kubelet ,k3s相关 | k3s master节点 |
slave01 | Ubuntu 20.04.4 LTS 20.04 | 模拟 | docker,kubelet, k3s相关 | k3s worker节点 |
slave02 | Ubuntu 20.04.4 LTS 20.04 | 模拟 | docker,kubelet,k3s相关 | k3s worker节点 |
二 实验事项
2.1 查看相关
kubectl get node #查看node
kubectl get node -o wide #查看扩展信息
kubectl get describe node master01 #查看 node master01 配置详情信息
kubectl get node slave01 -o yaml # 查看slave01 yaml格式
kubectl get node --show-labels. # 多现实标签信息
其它:namespace、deployment、pod等资源,都可以通过上面类似信息查看
# 查看node
ubuntu@master01:~$ sudo kubectl get node
NAME STATUS ROLES AGE VERSION
slave02 Ready <none> 332d v1.23.3+k3s1
master01 Ready control-plane,master 332d v1.23.3+k3s1
slave01 Ready <none> 332d v1.23.3+k3s1
ubuntu@master01:~$
#查看node详情
ubuntu@master01:~$ sudo kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master01 Ready control-plane,master 332d v1.23.3+k3s1 192.168.64.45 <none> Ubuntu 20.04.4 LTS 5.4.0-137-generic containerd://1.5.9-k3s1
slave01 Ready <none> 332d v1.23.3+k3s1 192.168.64.46 <none> Ubuntu 20.04.4 LTS 5.4.0-137-generic containerd://1.5.9-k3s1
slave02 Ready <none> 332d v1.23.3+k3s1 192.168.64.47 <none> Ubuntu 20.04.4 LTS 5.4.0-137-generic containerd://1.5.9-k3s1
ubuntu@master01:~$
#查看具体标签
ubuntu@master01:~$ sudo kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master01 Ready control-plane,master 332d v1.23.3+k3s1 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/instance-type=k3s,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=true,node-role.kubernetes.io/master=true,node.kubernetes.io/instance-type=k3s
slave01 Ready <none> 332d v1.23.3+k3s1 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/instance-type=k3s,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=slave01,kubernetes.io/os=linux,node.kubernetes.io/instance-type=k3s
slave02 Ready <none> 332d v1.23.3+k3s1 beta.kubernetes.io/arch=arm64,beta.kubernetes.io/instance-type=k3s,beta.kubernetes.io/os=linux,kubernetes.io/arch=arm64,kubernetes.io/hostname=slave02,kubernetes.io/os=linux,node.kubernetes.io/instance-type=k3s
ubuntu@master01:~$
#yaml格式
ubuntu@master01:~$ sudo kubectl get node master01 -o yaml
apiVersion: v1
kind: Node
metadata:
annotations:
flannel.alpha.coreos.com/backend-data: '{"VNI":1,"VtepMAC":"6a:ad:2e:8e:81:15"}'
flannel.alpha.coreos.com/backend-type: vxlan
flannel.alpha.coreos.com/kube-subnet-manager: "true"
省略
#查看node详情内容
ubuntu@master01:~$ sudo kubectl describe node master01
Name: master01
Roles: control-plane,master
Labels: beta.kubernetes.io/arch=arm64
beta.kubernetes.io/instance-type=k3s
beta.kubernetes.io/os=linux
kubernetes.io/arch=arm64
kubernetes.io/hostname=master01
kubernetes.io/os=linux
node-role.kubernetes.io/control-plane=true
node-role.kubernetes.io/master=true
node.kubernetes.io/instance-type=k3s
Annotations: flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"6a:ad:2e:8e:81:15"}
flannel.alpha.coreos.com/backend-type: vxlan
flannel.alpha.coreos.com/kube-subnet-manager: true
flannel.alpha.coreos.com/public-ip: 192.168.64.45
k3s.io/hostname: master01
k3s.io/internal-ip: 192.168.64.45
k3s.io/node-args: ["server"]
省略
2.2 创建相关
#命令直接创建
ubuntu@master01:~$ sudo kubectl create namespace testlab
namespace/testlab created
#使用yaml格式创建
ubuntu@master01:~/learn$ cat testlab2.yaml
apiVersion: v1
kind: Namespace
metadata:
name: testlab2
ubuntu@master01:~/learn$ sudo kubectl apply -f testlab2.yaml
namespace/testlab2 created
ubuntu@master01:~/learn$ sudo kubectl get ns
NAME STATUS AGE
default Active 332d
kube-system Active 332d
kube-public Active 332d
kube-node-lease Active 332d
test Active 30m
testlab Active 101s
testlab2 Active 7s
ubuntu@master01:~/learn$
2.3 修改或删除
#删除namespae testlab
ubuntu@master01:~/learn$ sudo kubectl delete ns testlab
namespace "testlab" deleted
ubuntu@master01:~/learn$
#命令修改
ubuntu@master01:~/learn$ sudo kubectl get ns testlab2 --show-labels
NAME STATUS AGE LABELS
testlab2 Active 4m41s kubernetes.io/metadata.name=testlab2
ubuntu@master01:~/learn$ sudo kubectl label ns testlab2 name=cka
namespace/testlab2 labeled
ubuntu@master01:~/learn$ sudo kubectl get ns testlab2 --show-labels
NAME STATUS AGE LABELS
testlab2 Active 5m5s kubernetes.io/metadata.name=testlab2,name=cka
ubuntu@master01:~/learn$ sudo kubectl label ns testlab2 name=cka1
error: 'name' already has a value (cka), and --overwrite is false
ubuntu@master01:~/learn$ sudo kubectl label ns testlab2 name=cka1 --overwrite
namespace/testlab2 labeled
ubuntu@master01:~/learn$ sudo kubectl get ns testlab2 --show-labels
NAME STATUS AGE LABELS
testlab2 Active 5m31s kubernetes.io/metadata.name=testlab2,name=cka1
ubuntu@master01:~/learn$
#yaml文件修改,直接编辑文件修改
ubuntu@master01:~/learn$ sudo kubectl apply -f testlab2.yaml
namespace/testlab2 configured
ubuntu@master01:~/learn$ cat testlab2.yaml
apiVersion: v1
kind: Namespace
metadata:
name: testlab2
labels: {
"env" : "prod"
}
ubuntu@master01:~/learn$ sudo kubectl get ns testlab2 --show-labels
NAME STATUS AGE LABELS
testlab2 Active 8m19s env=prod,kubernetes.io/metadata.name=testlab2,name=cka1
ubuntu@master01:~/learn$
标签:node,复习,kubernetes,master01,基础知识,testlab2,io,ubuntu,k8s
From: https://www.cnblogs.com/vbear/p/17100365.html