kubernetes yml样例

简介

Kubernetes 对象语法

在k8s中,kubernetes对象是持久化的试题,可以表示整个集群的状态:哪些容器化应用在运行,可以被应用使用的资源,关于应用裕兴表现的策略,比如重启策略、升级策略,以及容错策略。

对象主要包含如下五部分内容:

 apiVersion:  创建该对象所使用的 Kubernetes API 的版本
 kind: 想要创建的对象的类别
 metadata: 唯一性标识对象的一些数据
 spec: 规约
 status: 状态,由kubernetes系统和组件设置并自动生成

Nginx 服务

  nginx-k8s.yaml



cephfs 挂载

apiVersion: v1
kind: Pod
metadata:
  name: cephfs
spec:
  containers:
  - name: cephfs-rw
    image: kubernetes/pause
    volumeMounts:
    - mountPath: "/mnt/cephfs"
      name: cephfs
  volumes:
  - name: cephfs
    cephfs:
      monitors:
      - 10.16.154.78:6789
      - 10.16.154.82:6789
      - 10.16.154.83:6789
      # by default the path is /, but you can override and mount a specific path of the filesystem by using the path attribute
      # path: /some/path/in/side/cephfs
      user: admin
      secretFile: "/etc/ceph/admin.secret"
      readOnly: true
apiVersion: v1
kind: Pod
metadata:
  name: cephfs2
spec:
  containers:
  - name: cephfs-rw
    image: kubernetes/pause
    volumeMounts:
    - mountPath: "/mnt/cephfs"
      name: cephfs
  volumes:
  - name: cephfs
    cephfs:
      monitors:
      - 10.16.154.78:6789
      - 10.16.154.82:6789
      - 10.16.154.83:6789
      user: admin
      secretRef:
        name: ceph-secret
      readOnly: true

ceph-secret.yml

apiVersion: v1
kind: Secret
metadata:
  name: ceph-secret
data:
  key: QVFCMTZWMVZvRjVtRXhBQTVrQ1FzN2JCajhWVUxSdzI2Qzg0SEE9PQ==
 * monitors: ceph 集群的额monitor.
 * path: 默认为:/,用户指定cephfs的目录.
 * user: The RADOS 用户名,默认为:admin. 
 * secretFile: keyring 文件路径. 默认为: /etc/ceph/user.secret.
 * secretRef: 指向ceph 认证secret。如果配置此项,覆盖secretFile.
 * readOnly: 文件系统是否为:readOnly.

PV样例

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2

PVC样例

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: cloned-pvc
spec:
  storageClassName: my-csi-plugin
  dataSource:
    name: existing-src-pvc-name
    kind: PersistentVolumeClaim
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

备注:从存在的pvc创建pvc

存储类样例

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
provisioner: kubernetes.io/rbd
parameters:
  monitors: 10.16.153.105:6789
  adminId: kube
  adminSecretName: ceph-secret
  adminSecretNamespace: kube-system
  pool: kube
  userId: kube
  userSecretName: ceph-secret-user
  userSecretNamespace: default
  fsType: ext4
  imageFormat: "2"
  imageFeatures: "layering"
* monitors: Ceph monitors, 都好分割. 参数必须.
* adminId: 能够在池中创建映像的Ceph客户端ID,默认为:admin 
* adminSecretName: adminId的secret名字. 参数必须。The provided secret must have type “kubernetes.io/rbd”.
* adminSecretNamespace: The namespace for adminSecretName. Default is “default”.
* pool: Ceph RBD pool. 默认为:“rbd”.
* userId: Ceph client ID that is used to map the RBD image. Default is the same as adminId.
* userSecretName: The name of Ceph Secret for userId to map RBD image. It must exist in the same namespace as PVCs. This parameter is required. The provided secret * must have type “kubernetes.io/rbd”, for example created in this way:
* 
* kubectl create secret generic ceph-secret --type="kubernetes.io/rbd" \
   --from-literal=key='QVFEQ1pMdFhPUnQrSmhBQUFYaERWNHJsZ3BsMmNjcDR6RFZST0E9PQ==' \
   --namespace=kube-system
* userSecretNamespace: userSecretName的命名空间.

* fsType: k8s支持的fsType. 默认为: "ext4".

* imageFormat: Ceph RBD 镜像格式, “1” or “2”. 默认为 “2”.

* imageFeatures: This parameter is optional and should only be used if you set imageFormat to “2”. Currently supported features are layering only. Default is “”, and * no features are turned on
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: slow
provisioner: kubernetes.io/aws-ebs
parameters:
  type: io1
  iopsPerGB: "10"
  fsType: ext4
* type: io1, gp2, sc1, st1. See AWS docs for details. Default: gp2.
* zone (Deprecated): AWS zone. If neither zone nor zones is specified, volumes are generally round-robin-ed across all active zones where Kubernetes cluster has a * node. zone and zones parameters must not be used at the same time.
* zones (Deprecated): A comma separated list of AWS zone(s). If neither zone nor zones is specified, volumes are generally round-robin-ed across all active zones * where Kubernetes cluster has a node. zone and zones parameters must not be used at the same time.
* iopsPerGB: only for io1 volumes. I/O operations per second per GiB. AWS volume plugin multiplies this with size of requested volume to compute IOPS of the volume * and caps it at 20 000 IOPS (maximum supported by AWS, see AWS docs. A string is expected here, i.e. "10", not 10.
* fsType: fsType that is supported by kubernetes. Default: "ext4".
* encrypted: denotes whether the EBS volume should be encrypted or not. Valid values are "true" or "false". A string is expected here, i.e. "true", not true.
* kmsKeyId: optional. The full Amazon Resource Name of the key to use when encrypting the volume. If none is supplied but encrypted is true, a key is generated by * AWS. See AWS docs for valid ARN value

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gold
provisioner: kubernetes.io/cinder
parameters:
  availability: nova
* availability: Availability Zone. If not specified, volumes are generally round-robin-ed across all active zones where Kubernetes cluster has a node.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
provisioner: kubernetes.io/vsphere-volume
parameters:
  diskformat: zeroedthick
* 备注:使用指定的磁盘格式创建StorageClass
* diskformat: thin, zeroedthick and eagerzeroedthick. Default: "thin"
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast
provisioner: kubernetes.io/vsphere-volume
parameters:
    diskformat: zeroedthick
    datastore: VSANDatastore
* datastore: The user can also specify the datastore in the StorageClass. The volume will be created on the datastore specified in the storage class, which in this case is VSANDatastore. This field is optional. If the datastore is not specified, then the volume will be created on the datastore specified in the vSphere config file used to initialize the vSphere Cloud Provider.

nginx-jboss-mysql

nginx-tomcat-mysql

elk

apiVersion: apps/v1
kind: Deployment

jumpserver

zabbix