博客
关于我
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/

你可能感兴趣的文章
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>