博客
关于我
kubernetes学习总结-4YAML语法
阅读量:779 次
发布时间:2019-03-24

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

YAML Syntax

YAML(Yet Another Markup Language)是一种常用的数据序列化语言,广泛应用于配置文件、项目管理和自动化脚本等领域。YAML 在 Kubernetes 和 Helm 等工具中具有重要地位。

YAML 结构

YAML 主有两种核心类型:字典和序列。

字典类似于 JSON 或 YAML 格式,通过键值对存储数据:

map:  one: 1  two: 2  three: 3

序列(列表)则通过逗号分隔来存储项:

sequence:  - one  - two  - three

YAML 格式符

YAML 还支持丰富的格式符,用于实现更复杂的数据格式处理,以下是常用的符号:

  • # 注释,支持单行注释,可以通过连字符开始(-)或numerator:
  • | 用于控制多行文本的空格, 無請 :優先以原始文本格式呈现。
    coffee: /  Latte  Cappuccino  Espresso#output:Latte\nCappuccino\nEspresso  coffee: |-  Latte  Cappuccino  Espresso#output: Latte\nCappuccino\nEspresso (with no trailing newline)coffee: |+  Latte  Cappuccino  Espresso#output: Latte\nCappuccino\nEspresso\n\r\n
### YAML 锚定(Anchors)YAML 提供了对值进行引用和再利用的机制, referred 为锚定。这种机制在多步骤流程中非常实用。```yamlcoffee: "yes, please"favorite: &favoriteCoffee "Cappucino"coffees:  - Latte  - *favoriteCoffee  - Espresso

上述 YAML 表示:

coffee: yes, pleasefavorite: Cappucinocoffees:  - Latte  - Cappucino  - Espresso

注意:在 Helm 和 Kubernetes 中,由于频繁读取、修改并重新生成 YAML 文件,锚定会被丢失,因此在这些环境下不宜过度使用。

Resource List Format

在 Kubernetes 中,资源清单文件(Resource Definition File)通常包含以下字段:

Parameter Name Explanation
containers[].name 容器名称
containers[].image 容器镜像名称
containers[].imagePullPolicy 镜像拉取策略
containers[].command[] 容器执行命令
containers[].args[] 容器启动参数
containers[].wolumeMounts[].name 挂载点名称
containers[].wolumeMounts[].mountPath 挂载路径
containers[].ports[].name 端口名称
containers[].ports[].containerPort 容器端口
containers[].ports[].hostPort 主机端口
containers[].ports[].protocol 端口协议
containers[].env[].name 环境变量名称
containers[].env[].value 环境变量值
containers[].resources.requests.cpu 请求CPU资源
containers[].resources.requests.memory 请求内存资源

Creating a Pod with YAML

以下是一个通过 YAML 创建 Pod 的示例配置文件:

apiVersion: v1kind: ReplicationControllermetadata:  name: kikisspec:  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/

你可能感兴趣的文章
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>