Pod API 的实现原理
官方文档 pors https://kubernetes.io/zh/docs/concepts/workloads/pods/.
1.在集群内 创建pod
test1.yml
apiVersion: v1
kind: Pod
metadata:
name: two-containers
spec:
restartPolicy: Never
volumes:
- name: shared-data
hostPath:
path: /data
containers:
- name: nginx-container
image: nginx
volumeMounts:
- name: shared-data
mountPath: /usr/share/nginx/html
- name: debian-container
image: debian
volumeMounts:
- name: shared-data
mountPath: /pod-data
command: ["/bin/sh"]
args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]
2.执行yaml文件
kubectl apply -f test1.yml
3.查看当前默认 pods
[root@k8s-master yaml]# kubectl get pods
NAME READY STATUS RESTARTS AGE
two-containers 0/2 ContainerCreating 0 36s
[root@k8s-master yaml]# kubectl get pods
NAME READY STATUS RESTARTS AGE
two-containers 1/2 NotReady 0 14m
4.查看创建容器的位置
[root@k8s-master yaml]# kubectl describe pods two-containers
Name: two-containers
Namespace: default
Priority: 0
Node: k8s-node2/10.9.29.107 #容器的位置
Start Time: Wed, 17 Mar 2021 22:17:16 -0400
...
5.查看容器挂载的内容
到对应机器上查看是否挂载
[root@k8s-node2 ~]# cat /data/index.html
Hello from the debian container
本文介绍了Kubernetes中Pod API的工作原理,通过一个具体的示例详细展示了如何在集群内部署Pod,包括创建Pod的YAML文件、执行部署命令、查看Pod状态及容器挂载路径等内容。
1879

被折叠的 条评论
为什么被折叠?



