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

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文件中

在这里插入图片描述

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值