Pod创建
# 创建命名空间
> 这里的kubens命令是我自行设置简短的,想设置的可以参考我的博客:https://www.cnblogs.com/kongshuo/p/17412322.html
[root@kmaster ~]# kubectl create ns kongshuo
namespace/kongshuo created
[root@kmaster ~]# kubens
calico-apiserver
calico-system
default
kongshuo
kube-node-lease
kube-public
kube-system
tigera-operator
[root@kmaster ~]# kubens kongshuo
Context "kubernetes-admin@kubernetes" modified.
Active namespace is "kongshuo".
[root@kmaster ~]# kubens
calico-apiserver
calico-system
default
kongshuo
kube-node-lease
kube-public
kube-system
tigera-operator
# 创建一个简单的nginx
[root@kmaster ~]# kubectl get pod
No resources found in kongshuo namespace.
[root@kmaster ~]# kubectl run pod1 --image nginx
pod/pod1 created
[root@kmaster ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
pod1 1/1 Running 0 24s
# 查看pod运行在哪个节点
[root@kmaster ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod1 1/1 Running 0 95s 10.244.69.201 knode2 <none> <none>
# 查看节点是否下载了nginx镜像
[root@knode2 ~]# crictl img
IMAGE TAG IMAGE ID SIZE
docker.io/calico/cni v3.25.0 d70a5947d57e5 88MB
docker.io/calico/csi v3.25.0 f37eacbb9a295 9.08MB
docker.io/calico/kube-controllers v3.25.0 5e785d005ccc1 31.3MB
docker.io/calico/node-driver-registrar v3.25.0 c14671fdda128 11.1MB
docker.io/calico/node v3.25.0 08616d26b8e74 87.2MB
docker.io/calico/pod2daemon-flexvol v3.25.0 ed8b7bbb113fe 7.08MB
docker.io/calico/typha v3.25.0 7b60c7012b1c9 28.5MB
docker.io/library/nginx latest 448a08f1d2f94 57MB
quay.io/tigera/operator v1.29.0 343ea4f89a32c 21.1MB
registry.aliyuncs.com/google_containers/coredns v1.9.3 5185b96f0becf 14.8MB
registry.aliyuncs.com/google_containers/kube-proxy v1.26.0 556768f31eb1d 21.5MB
registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12e 302kB
# 查看pod详细信息
[root@kmaster ~]# kubectl describe pod pod1
Name: pod1
Namespace: kongshuo
Priority: 0
Service Account: default
Node: knode2/192.168.100.182
Start Time: Fri, 19 May 2023 12:03:29 +0800
Labels: run=pod1
Annotations: cni.projectcalico.org/containerID: 1e53a3fe0b3b6f7d8983709d51ace6114c3f057dc5d43bf8ef1c730234ae7675
cni.projectcalico.org/podIP: 10.244.69.202/32
cni.projectcalico.org/podIPs: 10.244.69.202/32
Status: Running
IP: 10.244.69.202
IPs:
IP: 10.244.69.202
Containers:
pod1:
Container ID: containerd://8d3910112bd21740735b125656e3b6cd8f88e890794c719a3cd9c441adab75fe
Image: nginx
Image ID: docker.io/library/nginx@sha256:480868e8c8c797794257e2abd88d0f9a8809b2fe956cbfbc05dcc0bca1f7cd43
Port: <none>
Host Port: <none>
State: Running
Started: Mon, 22 May 2023 09:20:54 +0800
Last State: Terminated
Reason: Unknown
Exit Code: 255
Started: Fri, 19 May 2023 12:03:41 +0800
Finished: Mon, 22 May 2023 09:19:39 +0800
Ready: True
Restart Count: 1
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-q62zp (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-q62zp:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2d21h default-scheduler Successfully assigned kongshuo/pod1 to knode2
Normal Pulling 2d21h kubelet Pulling image "nginx"
Normal Pulled 2d21h kubelet Successfully pulled image "nginx" in 11.222394648s (11.222400274s including waiting)
Normal Created 2d21h kubelet Created container pod1
Normal Started 2d21h kubelet Started container pod1
Normal SandboxChanged 3m26s (x3 over 4m23s) kubelet Pod sandbox changed, it will be killed and re-created.
Normal Pulling 3m25s kubelet Pulling image "nginx"
Normal Pulled 3m23s kubelet Successfully pulled image "nginx" in 2.40067693s (2.400682318s including waiting)
Normal Created 3m23s kubelet Created container pod1
Normal Started 3m22s kubelet Started container pod1