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

你可能感兴趣的文章
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>