kubernetes如何快速编写yaml文件
有两种方式
1、使用kubectl create命令生成yaml
[root@test yaml]# kubectl create deployment my-dep --image=nginx -o yaml --dry-run >web.yaml W1214 12:23:36.642511 6822 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client. [root@mvpemen-game--test yaml]# cat web.yaml apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: my-dep name: my-dep spec: replicas: 1 selector: matchLabels: app: my-dep strategy: {} template: metadata: creationTimestamp: null labels: app: my-dep spec: containers: - image: nginx name: nginx resources: {} status: {}
2、将部署好的医院使用kubectl get命令导出yaml文件
[root@test yaml]# kubectl get deployment my-dep -o yaml >my2.yaml [root@test yaml]# cat my2.yaml apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "1" kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"creationTimestamp":null,"labels":{"app":"my-dep"},"name":"my-dep","namespace":"default"},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"my-dep"}},"strategy":{},"template":{"metadata":{"creationTimestamp":null,"labels":{"app":"my-dep"}},"spec":{"containers":[{"image":"nginx","name":"nginx","resources":{}}]}}},"status":{}} creationTimestamp: "2020-12-14T04:36:31Z" generation: 1 labels: app: my-dep managedFields: - apiVersion: apps/v1 fieldsType: FieldsV1 fieldsV1: f:metadata: f:annotations: .: {} f:kubectl.kubernetes.io/last-applied-configuration: {} f:labels: .: {} f:app: {} f:spec: f:progressDeadlineSeconds: {} f:replicas: {} f:revisionHistoryLimit: {} f:selector: f:matchLabels: .: {} f:app: {} f:strategy: f:rollingUpdate: .: {} f:maxSurge: {} f:maxUnavailable: {} f:type: {} f:template: f:metadata: f:labels: .: {} f:app: {} f:spec: f:containers: k:{"name":"nginx"}: .: {} f:image: {} f:imagePullPolicy: {} f:name: {} f:resources: {} f:terminationMessagePath: {} f:terminationMessagePolicy: {} f:dnsPolicy: {} f:restartPolicy: {} f:schedulerName: {} f:securityContext: {} f:terminationGracePeriodSeconds: {} manager: kubectl-client-side-apply operation: Update time: "2020-12-14T04:36:31Z" - apiVersion: apps/v1 fieldsType: FieldsV1 fieldsV1: f:metadata: f:annotations: f:deployment.kubernetes.io/revision: {} f:status: f:availableReplicas: {} f:conditions: .: {} k:{"type":"Available"}: .: {} f:lastTransitionTime: {} f:lastUpdateTime: {} f:message: {} f:reason: {} f:status: {} f:type: {} k:{"type":"Progressing"}: .: {} f:lastTransitionTime: {} f:lastUpdateTime: {} f:message: {} f:reason: {} f:status: {} f:type: {} f:observedGeneration: {} f:readyReplicas: {} f:replicas: {} f:updatedReplicas: {} manager: kube-controller-manager operation: Update time: "2020-12-14T04:36:37Z" name: my-dep namespace: default resourceVersion: "1046241" selfLink: /apis/apps/v1/namespaces/default/deployments/my-dep uid: e5b3b504-8963-4e21-9605-3060cc423e45 spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: my-dep strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: my-dep spec: containers: - image: nginx imagePullPolicy: Always name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 1 conditions: - lastTransitionTime: "2020-12-14T04:36:37Z" lastUpdateTime: "2020-12-14T04:36:37Z" message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: "True" type: Available - lastTransitionTime: "2020-12-14T04:36:31Z" lastUpdateTime: "2020-12-14T04:36:37Z" message: ReplicaSet "my-dep-5b7868d854" has successfully progressed. reason: NewReplicaSetAvailable status: "True" type: Progressing observedGeneration: 1 readyReplicas: 1 replicas: 1 updatedReplicas: 1
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!