Kubernetes 之 YAML 语法
Kubernetes 语法 yaml
2023-06-13 09:15:42 时间
YAML 是一种非常简洁/强大/专门用来写配置文件的语言!
YAML 全称是 ”YAML Ain’t a Markup Language” 的递归缩写,该语言的设计参考了 JSON / XML 和 SDL 等语言,强调以数据为中心,简洁易读,编写简单。
YAML 语法特性学过编程的人理解起来应该非常容易
大小写敏感 通过缩进表示层级关系 禁止使用tab缩进,只能使用空格键 缩进的空格数目不重要,只要相同层级左对齐 使用#表示注释# yaml languages: - Ruby - Perl - Python websites: YAML: yaml.org Ruby: ruby-lang.org Python: python.org Perl: use.perl.org # Json languages: [ Ruby, Perl, Python websites: { YAML: yaml.org, Ruby: ruby-lang.org, Python: python.org, Perl: use.perl.org对象: 键值对的字典 数组: 一组按次序排列的列表 纯量: 单个的且不可再分的值
# 纯量 hello - Cat - Dog - Goldfish animal: pets单引号 : 特殊字符作为普通字符串处理 双引号 : 特殊字符作为本身想表示的意思
# 单引号 name: Hi,/nTom # 双引号 name: "Hi,/nTom"内置类型列表
# YAML允许使用个感叹号(!)强制转换数据类型 # 单叹号通常是自定义类型,双叹号是内置类型 money: !!str date: !Boolean
# 注意“|”与文本之间须另起一行 # 使用|标注的文本内容缩进表示的块,可以保留块中已有的回车换行 value: | hello world! # 输出结果 # hello 换行 world!!
# +表示保留文字块末尾的换行 # -表示删除字符串末尾的换行 value: | hello value: |- hello value: |+ hello # 输出结果 # hello/n hello hello/n/n
# 注意“ ”与文本之间的空格 # 使用 标注的文本内容缩进表示的块,将块中回车替换为空格最终连接成一行 value: hello world! # 输出结果 # hello 空格 world!锚点与引用
# 复制代码注意*引用部分不能追加内容 # 使用 定义数据锚点,即要复制的数据 # 使用*引用锚点数据,即数据的复制目的地 name: a yaml book: *a books: - java - *a - python # 输出结果 book: yaml books:[java, yaml, python]YAML 实例说明
光说不练假把式 = JS-Yaml 官网实例地址 https://nodeca.github.io/js-yaml
# Collection Types ############################################################# ################################################################################ # http://yaml.org/type/map.html -----------------------------------------------# # Unordered set of key: value pairs. Block style: !!map Clark: Evans Ingy: döt Net Oren: Ben-Kiki Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki } # http://yaml.org/type/omap.html ----------------------------------------------# omap: # Explicitly typed ordered map (dictionary). Bestiary: !!omap - aardvark: African pig-like ant eater. Ugly. - anteater: South-American ant eater. Two species. - anaconda: South-American constrictor snake. Scaly. # Etc. # Flow style Numbers: !!omap [one: 1, two: 2, three: 3] # http://yaml.org/type/pairs.html ---------------------------------------------# pairs: # Explicitly typed pairs. Block tasks: !!pairs - meeting: with team. - meeting: with boss. - break: lunch. - meeting: with client. Flow tasks: !!pairs [meeting: with team, meeting: with boss] # http://yaml.org/type/set.html -----------------------------------------------# # Explicitly typed set. baseball players: !!set ? Mark McGwire ? Sammy Sosa ? Ken Griffey # Flow style baseball teams: !!set { Boston Red Sox, Detroit Tigers, New York Yankees } # http://yaml.org/type/seq.html -----------------------------------------------# # Ordered sequence of nodes Block style: !!seq - Mercury # Rotates - no light/dark sides. - Venus # Deadliest. Aptly named. - Earth # Mostly dirt. - Mars # Seems empty. - Jupiter # The king. - Saturn # Pretty. - Uranus # Where the sun hardly shines. - Neptune # Boring. No rings. - Pluto # You call this a planet? Flow style: !!seq [ Mercury, Venus, Earth, Mars, # Rocks Jupiter, Saturn, Uranus, Neptune, # Gas Pluto, ] # Overrated # Scalar Types ################################################################# ################################################################################ # http://yaml.org/type/bool.html ----------------------------------------------# bool: - true - True - TRUE - false - False - FALSE # http://yaml.org/type/float.html ---------------------------------------------# float: canonical: 6.8523015e+5 exponentioal: 685.230_15e+03 fixed: 685_230.15 sexagesimal: 190:20:30.15 negative infinity: -.inf not a number: .NaN # http://yaml.org/type/int.html -----------------------------------------------# canonical: 685230 decimal: +685_230 octal: 02472256 hexadecimal: 0x_0A_74_AE binary: 0b1010_0111_0100_1010_1110 sexagesimal: 190:20:30 # http://yaml.org/type/merge.html ---------------------------------------------# merge: - CENTER { x: 1, y: 2 } - LEFT { x: 0, y: 2 } - BIG { r: 10 } - SMALL { r: 1 } # All the following maps are equal: - # Explicit keys x: 1 y: 2 r: 10 label: nothing - # Merge one map : *CENTER r: 10 label: center - # Merge multiple maps : [*CENTER, *BIG] label: center/big - # Override function foobar() { return Wow! JS-YAML Rocks!; # Custom types ################################################################# ################################################################################ # JS-YAML allows you to specify a custom YAML types for your structures. # This is a simple example of custom constructor defined in `js/demo.js` for # custom `!sexy` type: # var SexyYamlType = new jsyaml.Type(!sexy, { # kind: sequence, # construct: function (data) { # return data.map(function (string) { return sexy + string; }); # }); # var SEXY_SCHEMA = jsyaml.Schema.create([ SexyYamlType ]); # result = jsyaml.load(yourData, { schema: SEXY_SCHEMA }); foobar: !sexy - bunny - chocolate
作者:Escape
文章来源:https://escapelife.github.io/posts/8032061c.html
(版权归原作者所有,侵删)
本文链接:http://www.yunweipai.com/39814.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/52850.html
javaKubernetespython相关文章
- Kubernetes-Deployment
- 22-kubernetes集群中进行etcd数据快照的备份恢复
- 基于Containerd部署Kubernetes
- 关于Kubernetes中kube-apiserver使用token、kubeconfig认证的一些笔记
- 二进制安装Kubernetes(k8s) v1.26.0 IPv4/IPv6双栈
- Kubernetes 的 CI/CD 管道概述
- 一文搞懂基于 Kube-Bench 评估 Kubernetes 安全性
- 为什么需要 Kubernetes 准入控制器
- 报告称Kubernetes 安全大量使用开源解决方案
- Kubernetes 1.26: 动态资源分配 Alpha API
- Kubernetes集群部署之六Flannel网络部署详解架构师