3.1 使用命令创建Pod(v1.18版本变化)
- 在 Kubernetes v1.18 之前,
kubectl run
命令用于创建 Deployment 控制器。 - 从 v1.18 版本开始,
kubectl run
命令改为用于创建 Pod。
3.1.1 创建名为 pod-nginx
的 Pod
[root@k8s-master1 ~]# kubectl run nginx1 --image=nginx:1.15-alpine
pod/nginx1 created
3.1.2 验证 Pod 创建
[root@k8s-master1 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx1 1/1 Running 0 41s
3.2 使用 YAML 文件创建 Pod
3.2.1 准备 YAML 文件
[root@k8s-master1 ~]# vim pod1.yml
apiVersion: v1 # API 版本
kind: Pod # 资源类型为 Pod
metadata:
name: pod-stress # 自定义 Pod 的名称
spec:
containers: # 定义 Pod 中包含的容器
- name: c1 # 自定义容器名称
image: polinux/stress # 启动容器的镜像名
command: ["stress"] # 自定义启动容器时执行的命令(类似 Dockerfile 中的 CMD)
args: ["--vm", "1", "--vm-bytes", "150M", "--vm-hang", "1"] # 自定义启动容器执行的命令参数
imagePullPolicy: IfNotPresent
# polinux/stress 镜像用于压力测试,启动容器时通过传递命令和参数来指定容器运行的压力
3.2.2 通过 YAML 文件创建 Pod
[root@k8s-master1 ~]# kubectl apply -f