2023-10-20 14:38:22
浏览数 (1)
资源清单文件Demo
代码语言:javascript
复制大部分资源的配置清单:
apiversion:group/version ( 可以使用kubectl api-versions查看当前支持的api版本)
kind:资源类别
metadata:元数据
name:唯一的
namespace:命名空间
lables:标签,键值数据
annotations:注解
ownerReferences:
resourceVersion:
selfLink:
uid:唯一标识
每个资源额引用PATH
/api/GROUP/VERSION/namespace/NAMESPACE/TYPE/NAME
spec:期望的状态 disired state
status:当前状态,current state,本自断由kubernetes集群维护
资源清单文件
代码语言:javascript
复制apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: nginx
- name: busybox
image: busybox
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
基于yaml资源清单文件创建
代码语言:javascript
复制[root@kuberneters-master yaml-file]# kubectl create -f pod-demo.yaml
pod/pod-demo created
[root@kuberneters-master yaml-file]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-ltkrp 1/1 Running 0 3d4h
nginx-6799fc88d8-m27bl 1/1 Running 1 17d
nginx-6799fc88d8-zg2x8 1/1 Running 1 17d
pod-demo 0/2 ContainerCreating 0 13s
[root@kuberneters-master yaml-file]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-ltkrp 1/1 Running 0 3d4h
nginx-6799fc88d8-m27bl 1/1 Running 1 17d
nginx-6799fc88d8-zg2x8 1/1 Running 1 17d
pod-demo 2/2 Running 0 25s
查看创建好的pod详情
代码语言:javascript
复制[root@kuberneters-master yaml-file]# kubectl describe pods pod-demo
Name: pod-demo
Namespace: default
Priority: 0
Node: kuberneters-node-2/192.168.3.105
Start Time: Tue, 22 Jun 2021 16:14:39 0800
Labels: app=myapp
tier=frontend
Annotations: <none>
Status: Running
IP: 10.244.2.6
IPs:
IP: 10.244.2.6
Containers:
myapp:
Container ID: docker://1cd8d468c12ca186f2b18b11cb708189107d48f33e270c3f8687040ac9596824
Image: nginx
Image ID: docker-pullable://nginx@sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Port: <none>
Host Port: <none>
State: Running
Started: Tue, 22 Jun 2021 16:14:46 0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dhqb7 (ro)
busybox:
Container ID: docker://6e44d214f9c14a30b5db945b60127049ea8903fbcba733fac4df3b27d233796b
Image: busybox
Image ID: docker-pullable://busybox@sha256:930490f97e5b921535c153e0e7110d251134cc4b72bbb8133c6a5065cc68580d
Port: <none>
Host Port: <none>
Command:
/bin/sh
-c
sleep 3600
State: Running
Started: Tue, 22 Jun 2021 16:14:55 0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dhqb7 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-dhqb7:
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 113s default-scheduler Successfully assigned default/pod-demo to kuberneters-node-2
Normal Pulling 111s kubelet Pulling image "nginx"
Normal Pulled 106s kubelet Successfully pulled image "nginx" in 4.454033806s
Normal Created 106s kubelet Created container myapp
Normal Started 106s kubelet Started container myapp
Normal Pulling 106s kubelet Pulling image "busybox"
Normal Pulled 97s kubelet Successfully pulled image "busybox" in 8.33975599s
Normal Created 97s kubelet Created container busybox
Normal Started 97s kubelet Started container busybox