01 查看各種資源
01-1 查看K8s集群的內置資源
[ root@master01 ~]
NAME SHORTNAMES APIVERSION NAMESPACED KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
圖1 查看K8s內置資源
01-2 查看具體的資源
[ root@master01 ~]
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy { "health" : "true" ,"reason" : "" }
圖2 使用全稱查看資源
[ root@master01 ~]
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy { "health" : "true" ,"reason" : "" }
圖3 使用簡稱查看資源
02 資源清單
02-1 資源清單結構
聲明資源API的版本號。
聲明資源的類型。
聲明資源你的元數據信息。這個元數據信息包括但不限于名稱,標簽,名稱空間,資源注解,資源的創建時間等。
聲明資源的期望狀態,用戶希望資源如何運行,比如Pod資源我們要考慮啟動容器名稱,容器使用的鏡像,啟動命令,暴露端口,環境變量,資源限制等。
資源的狀態,一般情況下,不需要維護該字段,是K8S集群內部自行維護。
[ root@master01 ~]
apiVersion : v1
kind : Node
metadata : annotations : flannel.alpha.coreos.com/backend-data : '{"VNI":1,"VtepMAC":"ba:64:c7:34:04:3d"}' flannel.alpha.coreos.com/backend-type : vxlanflannel.alpha.coreos.com/kube-subnet-manager : "true" flannel.alpha.coreos.com/public-ip : 172.2.25.52kubeadm.alpha.kubernetes.io/cri-socket : /var/run/dockershim.socknode.alpha.kubernetes.io/ttl : "0" volumes.kubernetes.io/controller-managed-attach-detach : "true" creationTimestamp : "2025-05-20T01:18:22Z" labels : beta.kubernetes.io/arch : amd64beta.kubernetes.io/os : linuxkubernetes.io/arch : amd64kubernetes.io/hostname : node01kubernetes.io/os : linuxname : node01resourceVersion : "16552" uid : 28bd4f86- dbf2- 48e0- ba4b- 8219dc2e14dd
spec : podCIDR : 172.22.2.0/24podCIDRs : - 172.22.2.0/24
status : addresses : - address : 172.2.25.52type : InternalIP- address : node01type : Hostnameallocatable : cpu : "2" ephemeral-storage : "139085221249" hugepages-1Gi : "0" hugepages-2Mi : "0" memory : 3758896Kipods : "110" capacity : cpu : "2" ephemeral-storage : 150917124Kihugepages-1Gi : "0" hugepages-2Mi : "0" memory : 3861296Kipods : "110" conditions : - lastHeartbeatTime : "2025-05-20T01:19:47Z" lastTransitionTime : "2025-05-20T01:19:47Z" message : Flannel is running on this nodereason : FlannelIsUpstatus : "False" type : NetworkUnavailable- lastHeartbeatTime : "2025-05-20T05:24:08Z" lastTransitionTime : "2025-05-20T01:18:22Z" message : kubelet has sufficient memory availablereason : KubeletHasSufficientMemorystatus : "False" type : MemoryPressure- lastHeartbeatTime : "2025-05-20T05:24:08Z" lastTransitionTime : "2025-05-20T01:18:22Z" message : kubelet has no disk pressurereason : KubeletHasNoDiskPressurestatus : "False" type : DiskPressure- lastHeartbeatTime : "2025-05-20T05:24:08Z" lastTransitionTime : "2025-05-20T01:18:22Z" message : kubelet has sufficient PID availablereason : KubeletHasSufficientPIDstatus : "False" type : PIDPressure- lastHeartbeatTime : "2025-05-20T05:24:08Z" lastTransitionTime : "2025-05-20T01:19:54Z" message : kubelet is posting ready statusreason : KubeletReadystatus : "True" type : ReadydaemonEndpoints : kubeletEndpoint : Port : 10250 images : - names : - harbor.likexy.com/likexy/registry.aliyuncs.com/google_containers/kube- proxy@sha256: 6eebf5374c8529ec87d29cc9348cc29989f42a2fc0ef1d7a31a6f3f45ba6e185- harbor.likexy.com/likexy/registry.aliyuncs.com/google_containers/kube- proxy: v1.23.17- registry.aliyuncs.com/google_containers/kube- proxy: v1.23.17sizeBytes : 110840983 - names : - harbor.likexy.com/likexy/flannel/flannel@sha256: f112dc48764d57eea8b4b04dc590779f04f77136e9f4b7e4eeefd32c6b547f73- flannel/flannel: v0.24.3- harbor.likexy.com/likexy/flannel/flannel: v0.24.3sizeBytes : 78604653 - names : - harbor.likexy.com/likexy/flannel/flannel@sha256: 5a39542e1f7746f523e459e440514614964db215b454d12ea7d713e0fa50a26f- flannel/flannel: v0.25.6- harbor.likexy.com/likexy/flannel/flannel: v0.25.6sizeBytes : 75116393 - names : - harbor.likexy.com/likexy/registry.aliyuncs.com/google_containers/coredns@sha256: 8916c89e1538ea3941b58847e448a2c6d940c01b8e716b20423d2d8b189d3972- harbor.likexy.com/likexy/registry.aliyuncs.com/google_containers/coredns: v1.8.6- registry.aliyuncs.com/google_containers/coredns: v1.8.6sizeBytes : 46829283 - names : - harbor.likexy.com/likexy/flannel/flannel- cni- plugin@sha256: a2e795c6d83e6db30637cad3cf7482eee41c0e2d1a58e53239b82c2442730001- flannel/flannel- cni- plugin: v1.5.1- flannel2- harbor.likexy.com/likexy/flannel/flannel- cni- plugin: v1.5.1- flannel2sizeBytes : 10632098 - names : - harbor.likexy.com/likexy/flannel/flannel- cni- plugin@sha256: 4163363bea19dee4ec4200b5bb9a20fa7dc460403d37800eac0a201f59faac5e- flannel/flannel- cni- plugin: v1.4.0- flannel1- harbor.likexy.com/likexy/flannel/flannel- cni- plugin: v1.4.0- flannel1sizeBytes : 9868473 - names : - harbor.likexy.com/likexy/registry.aliyuncs.com/google_containers/pause@sha256: 74bf6fc6be13c4ec53a86a5acf9fdbc6787b176db0693659ad6ac89f115e182c- harbor.likexy.com/likexy/registry.aliyuncs.com/google_containers/pause: 3.6 - registry.aliyuncs.com/google_containers/pause: 3.6 sizeBytes : 682696 nodeInfo : architecture : amd64bootID : fae0a0e3- 037b- 4a9c- a574- afd1914e5cd8containerRuntimeVersion : docker: //20.10.24kernelVersion : 3.10.0- 1160.el7.x86_64kubeProxyVersion : v1.23.17kubeletVersion : v1.23.17machineID : 6fdc18189448460d883a97826be9e74doperatingSystem : linuxosImage : CentOS Linux 7 (Core)systemUUID : 1CC24D56- C740- 5429- D505- DCA720499290
02-2 K8s資源的增刪改查
02-2.1 創建資源
[ root@master01 yaml]
pod/likexy created
圖4 根據yaml文件創建資源
02-2.2 刪除資源
[ root@master01 yaml]
pod "likexy" deleted
圖5 根據yaml文件刪除
[ root@master01 yaml]
[ root@master01 yaml]
圖6 使用命令刪除
02-2.3 修改資源
圖7 修改Yaml后重新創建資源
02-2.4 查看資源
[ root@master01 yaml]
NAME READY STATUS RESTARTS AGE
likexy 1 /1 Running 0 12m
likexy1 1 /1 Running 0 11m
[ root@master01 yaml]
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
likexy 1 /1 Running 0 12m 172.22 .4.3 node03 < none> < none>
likexy1 1 /1 Running 0 11m 172.22 .2.3 node01 < none> < none>
圖8 查看Pod資源和其詳細信息
圖9 使用Curl測試,可以測試出內容
03 K8s使用宿主機網絡
圖10 創建Pod,網絡選用宿主機網絡
圖11 Curl宿主機IP是能夠成功訪問的