美文网首页
K8S yaml格式讲解

K8S yaml格式讲解

作者: 运维之美 | 来源:发表于2019-11-20 15:38 被阅读0次

1、yaml配置文件举例

apiVersion: v1                      #当前配置格式的版本
kind: Deployment                #kind是要创建的资源类型,这里是deployment
metadata:                           #该资源的元数据,name是必需的元素
  name: rc-nginx           
spec:                                   #spec部分是定义的deployment的规格说明               
  replicas: 2                          #replicas是副本数量,默认时1,此处配置为双副本         
  template:                          #定义pod的模板
    metadata:                  #定义pod的元数据,至少要定义一个label,label的key和元数据可以任意指定
      labels:                  
        app: rc-nginx         
    spec:                        #描述pod的规格,定义的name和images都是必需的
      containers:              
      - name: nginx            
        image: nginx

2、持久化卷

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv002
labels:
release: stable
spec:
capacity:
  storage: 5Gi
accessModes:
  - ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
  path: /tmp/data
  server: 172.17.0.2 

accessModes
用于定义资源的访问方式,受限于存储底层的支持,访问方式包括以下几种:

ReadWriteOnce – 被单个节点mount为读写rw模式
ReadOnlyMany – 被多个节点mount为只读ro模式
ReadWriteMany – 被多个节点mount为读写rw模式

persistentVolumeReclaimPolicy

用于定义资源的回收方式,也首先与存储底层的支持,现有的回收策略:
Retain – 手动回收
Recycle – 删除数据 (“rm -rf /thevolume/*”)
Delete – 通过存储后端删除卷,后端存储例如AWS EBS, GCE PD或Cinder等。

相关文章

网友评论

      本文标题:K8S yaml格式讲解

      本文链接:https://www.haomeiwen.com/subject/yvdoictx.html