博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kubernetes学习总结-4YAML语法
阅读量:775 次
发布时间:2019-03-24

本文共 2311 字,大约阅读时间需要 7 分钟。

目录

1、yaml语法

  • 两种类型:字典和序列
map:  one: 1  two: 2  three: 3sequence:  - one  - two  - three
  • 格式符
coffee: /  Latte  Cappuccino  Espresso#output:Latte\nCappuccino\nEspresso\ncoffee: |-  Latte  Cappuccino  Espresso#output: Latte\nCappuccino\nEspresso (with no trailing \n).减号表示减去末尾换行符(不换行)coffee: |+  Latte  Cappuccino  Espresso#output: Now the value of coffee will be Latte\nCappuccino\nEspresso\n\n\n.加号表示加上末尾换行符(换行)
  • YAML Anchors

1、YAML规范提供了一种存储对值的引用,并在以后通过引用引用该值的方法。YAML将此称为“锚定”:

The YAML spec provides a way to store a reference to a value, and later refer to that value by reference. YAML refers to this as “anchoring”:
2、就是先通过引用赋值,然后通过取址的方式取得值

coffee: "yes, please"favorite: &favoriteCoffee "Cappucino" #引用赋值coffees:  - Latte  - *favoriteCoffee #取址来取值  - Espresso  #上面表达式等同为coffee: yes, pleasefavorite: Cappucinocoffees:- Latte- Cappucino- Espresso

注意:Because Helm and Kubernetes often read, modify, and then rewrite YAML files, the anchors will be lost.由于Helm和Kubernetes经常读取,修改然后重写YAML文件,因此锚点将丢失。

2、 资源清单格式

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

apiversion: group/apiversionversionskind: metadata:  name:  namespace:  labels  annotationsspec:
参数名 说明
spec.container[]
spec.container[].name
spec.container[].image
spec.container[].imagePullPolicy
spec.container[].command[]
spec.container[].args[]
spec.container[].workingDir
spec.container[].wolumeMounts[]
spec.container[].wolumeMounts[].name
spec.container[].wolumeMounts[].mountPath
spec.container[].wolumeMounts[].readOnly
spec.container[].ports[]
spec.container[].ports[].name
spec.container[].ports[].containerPort
spec.container[].ports[].hostPort
spec.container[].ports[].protocol
spec.container[].env[]
spec.container[].env[].name
spec.container[].env[].value
spec.container[].resources.limits
spec.container[].resources.limits.cpu
spec.container[].resources.limits.memory
spec.container[].resources.requests
spec.container[].resources.requests.cpu
spec.container[].resources.requests.memory
spec.nodeSelector
spec.imagePullsecrets
spec.hostNetwork

3、通过YAML创建Pod

apiVersion: v1kind: ReplicationControllermetadata:  name: kikispec:  replicas: 3  selector:    app: kiki  template:    metadata:      labels:        app: kiki    spec:      containers:      - name: kiki        image: centos        imagePullPolicy: IfNotPresent        command:         - "/bin/sh"        - "-c"        - "sleep 3600"

转载地址:http://qxnkk.baihongyu.com/

你可能感兴趣的文章