k8s-如何快速编写yaml文件(新手)

1、使用kubectl create 命令生成yaml文件

kubectl create depolyment web --image=nginx -o yaml --dty-run

depolyment:工作负载
--image=nginx:这个为对应镜像是nginx,
-o yaml :会把这个操作用yaml的格式生成出来,
--dty-run :尝试运行,并不正在运行(空跑)
[root@k8s-master ~]# kubectl create deployment web --image=nginx -o yaml --dry-run 
W1121 13:55:03.336877    3558 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: web
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: web
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

但是这个过程并没有在集群中执行,只是把结果通过yaml格式的方式输出出来,包括咱们可把它输出到文件里

[root@k8s-master ~]# kubectl create deployment web --image=nginx -o yaml --dry-run >>web.yaml

在这里插入图片描述

2、使用kubectl get 命令导出yaml文件

场景:适用于部署好的项目,可以把部署好的项目中的yaml文件导出出来,实际效果比较实用

[root@k8s-master ~]# kubectl get deployment nginx -o yaml >>web2.yaml
查看depolyment里的pod,选择pod:nginx 
-o yaml 指定输出为yaml格式
输出到web2.yaml文件中

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐