[关闭]
@zhangyy 2020-07-01T10:57:55.000000Z 字数 2009 阅读 178

kubernetes 的 yaml格式应用

kubernetes系列


  • 一: kubernetes yaml 配置文件

一: kubernetes yaml 配置文件

1.1 yaml 语言

  1. YAML 是一种简洁的非标记语言。
  2. 语法格式:
  3. 缩进表示层级关系
  4. 不支持制表符“tab”缩进,使用空格缩进
  5. 通常开头缩进 2 个空格
  6. 字符后缩进 1 个空格,如冒号、逗号等
  7. “---” 表示YAML格式,一个文件的开始
  8. “#”注释

  1. nignx Demo 配置
  2. vim nginx-deployment.yaml
  3. ---
  4. apiVersion: apps/v1
  5. kind: Deployment
  6. metadata:
  7. name: nginx-deployment
  8. labels:
  9. app: nginx
  10. spec:
  11. replicas: 3
  12. selector:
  13. matchLabels:
  14. app: nginx
  15. template:
  16. metadata:
  17. labels:
  18. app: nginx
  19. spec:
  20. containers:
  21. - name: nginx
  22. image: nginx:1.15.4
  23. ports:
  24. - containerPort: 80
  25. ---
  26. apiVersion: v1
  27. kind: Service
  28. metadata:
  29. name: nginx-service
  30. labels:
  31. app: nginx
  32. spec:
  33. type: NodePort
  34. ports:
  35. - port: 80
  36. targetPort: 80
  37. selector:
  38. app: nginx
  39. ----

  1. kubectl create -f nginx-deployment.yaml

image_1dkuubeou7oj196k1kt31tef1ecp9.png-97.9kB

image_1dkuubuepam42g3h41qsd3n7m.png-196.6kB

image_1dkuuch50ods1dbv1kbkc1k9vo13.png-145kB

1.2: 配置文件的解释

image_1dkuuhjp6bo010oj1ls5ot317al1g.png-285.7kB

图片.png-118.2kB

1.3:YAML配置文件的生成

  1. run命令生成
  2. kubectl run --image=nginx my-deploy -o yaml --dry-run > my-deploy.yaml
  3. get命令导出
  4. kubectl get my-deploy/nginx -o=yaml --export > my-deploy.yaml
  5. Pod容器的字段拼写忘记了
  6. kubectl explain pods.spec.containers

  1. kubectl run --image=nginx my-deploy -o yaml --dry-run > my-deploy.yaml

image_1dkuvb72h1av81d0l155vlcs1o311t.png-111kB

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. creationTimestamp: null
  5. labels:
  6. run: my-deploy
  7. name: my-deploy
  8. spec:
  9. replicas: 1
  10. selector:
  11. matchLabels:
  12. run: my-deploy
  13. strategy: {}
  14. template:
  15. metadata:
  16. creationTimestamp: null
  17. labels:
  18. run: my-deploy
  19. spec:
  20. containers:
  21. - image: nginx
  22. name: my-deploy
  23. resources: {}
  24. status: {}
  25. ---

image_1dkuvce8l4r714vb1lif7ohei32a.png-212.4kB

  1. kubectl get deploy/nginx -o=yaml --export > my-deploy.yaml

image_1dkv2bvkb1q3j1ldv163jbholg137.png-69.7kB

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. deployment.kubernetes.io/revision: "1"
  6. creationTimestamp: null
  7. generation: 1
  8. labels:
  9. run: nginx
  10. name: nginx
  11. selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/nginx
  12. spec:
  13. progressDeadlineSeconds: 600
  14. replicas: 3
  15. revisionHistoryLimit: 10
  16. selector:
  17. matchLabels:
  18. run: nginx
  19. strategy:
  20. rollingUpdate:
  21. maxSurge: 25%
  22. maxUnavailable: 25%
  23. type: RollingUpdate
  24. template:
  25. metadata:
  26. creationTimestamp: null
  27. labels:
  28. run: nginx
  29. spec:
  30. containers:
  31. - image: nginx:1.14
  32. imagePullPolicy: IfNotPresent
  33. name: nginx
  34. ports:
  35. - containerPort: 80
  36. protocol: TCP
  37. resources: {}
  38. terminationMessagePath: /dev/termination-log
  39. terminationMessagePolicy: File
  40. dnsPolicy: ClusterFirst
  41. restartPolicy: Always
  42. schedulerName: default-scheduler
  43. securityContext: {}
  44. terminationGracePeriodSeconds: 30
  45. status: {}


添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注