Перейти к содержанию

YAML examples

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  labels:
    tier: frontend
    app: nginx
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 3
  template:
    metadata:
      name: nginx-2
      labels:
        app: myapp
    spec:
      containers:
        - name: nginx
          image: nginx

replicaset.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-replicaset
  labels:
    app: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 3  # number of replicas
  template:  # POD template to be replicated
    metadata:
      name: nginx-2
      labels:
        app: myapp
    spec:
      containers:
        - name: nginx
          image: nginx

pod.yaml

Open pod.yaml in GitLab

compute_quota.yaml

apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: dev
spec:
  hard:
    pods: "10"
    requests.cpu: "4"
    requests.memory: 5Gi
    limits.cpu: "10"
    limits.memory: 10 Gi

my_app_secret_data.yaml

apiVersion: v1
kind: Secret
metadata:
  name: my-app-secret
data:
  DB_HOST: cG9zdGdyZXNxbF9ob3N0bmFtZQ== # postgresql_hostname
  DB_USER: cG9zdGdyZXM=  # postgres
  DB_PASSWORD: aGFja21l  # hackme

apiVersion

Kind Version
POD v1
Service v1
ResourceQuota v1
ReplicaSet apps/v1
Deployment apps/v1

Static Provisioning: PV → PVC → POD

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-vol1
spec:
  accessModes:
    -  ReadWriteOnce  # refers to pvc.yaml
  capacity:
    storage: 500Mi  # refers to pvc.yaml
  gcePersistentDisk:
    pdName: pd-disk
    fsType: ext4
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-volume  # refers to pod.yaml → spec → volumes → persistentVolumeClaim → claimName
spec:
  accessModes:
    -  ReadWriteOnce  # refers to pv.yaml
  storageClassName: google-storage
  resources:
    requests:
      storage: 500Mi  # refers to pv.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mysql
spec:
  containers:
    - name: mysql
      image: mysql
      volumeMounts:
        - mountPath: /var/lib/mysql
          name: data-volume
  volumes:
    - name: data-volume
      persistentVolumeClaim:
        claimName: data-volume  # refers to pvc.yaml → metadata → name

Dynamic Provisioning: SC → PVC → POD

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: google-storage
provisioner: kubernetes.io/gce-pd
volumeBindingMode: WaitForFirstConsumer
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-volume  # refers to pod.yaml → spec → volumes → persistentVolumeClaim → claimName
spec:
  accessModes:
    -  ReadWriteOnce  # refers to sc.yaml
  storageClassName: google-storage
  resources:
    requests:
      storage: 500Mi
apiVersion: v1
kind: Pod
metadata:
  name: mysql
spec:
  containers:
    - name: mysql
      image: mysql
      volumeMounts:
        - mountPath: /var/lib/mysql
          name: data-volume
  volumes:
    - name: data-volume
      persistentVolumeClaim:
        claimName: data-volume  # refers to pvc.yaml → metadata → name

Dynamic Provisioning: StorageClass → StatefulSet

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: google-storage
provisioner: kubernetes.io/gce-pd
volumeBindingMode: WaitForFirstConsumer
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  serviceName: mysql-h
  replicas: 3
  podManagementPolicy: OrderedReady
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: data-volume
  volumeClaimTemplates:
    - metadata:
        name: data-volume
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: google-storage
        resources:
          requests:
            storage: 500Mi