Kubernetes StatefulSet Manifest: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 15: Line 15:
   serviceName: postgresql-headless
   serviceName: postgresql-headless
   [[#.spec.selector|selector]]:
   [[#.spec.selector|selector]]:
     [[#.spec.selector.matchLabels|matchLabels]]: <font color=teal># all labels declared here must exists and have same corresponding values in the template.metadata.labels section below</font>
     [[#.spec.selector.matchLabels|matchLabels]]: <font color=teal># all labels declared here must exists and have same corresponding values in the [[#spec_template_metadata_labels|template.metadata.labels]] section below</font>
       app: postgresql
       app: postgresql
       role: master   
       role: master   
Line 24: Line 24:
     metadata:
     metadata:
       name: postgresql
       name: postgresql
       [[#.spec.template.metadata.labels|labels]]:
       <span id='spec_template_metadata_labels'></span>[[#.spec.template.metadata.labels|labels]]:
         app: postgresql
         app: postgresql
         role: master
         role: master

Revision as of 20:43, 17 March 2020

External

Internal

Example

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgresql
  labels:
    color: blue
spec:
  replicas: 1
  serviceName: postgresql-headless
  selector:
    matchLabels: # all labels declared here must exists and have same corresponding values in the template.metadata.labels section below
      app: postgresql
      role: master   
  podManagementPolicy: OrderedReady
  updateStrategy: 
    type: RollingUpdate
  template:
    metadata:
      name: postgresql
      labels:
        app: postgresql
        role: master
        color: blue 
    spec:
      containers:
        - ...
      initContainers:
        - ...
      dnsPolicy:  ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: ...
      terminationGracePeriodSeconds: ...
  volumeClaimTemplates:
    # for details see Persistent Volume Claim Manifest
    - metadata:
        name: data
      spec:
        volumeMode: Filesystem
        # Optionally a storage class can be specified, otherwise the default storage class will be used
        # storageClassName: manual-local-storage
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 8Gi

.spec Elements

.spec.selector

.spec.selector.matchLabels


The labels declared in this section must exist also in the .spec.template.metadata.labels section, and have the same corresponding values, otherwise the StatefulSet deployment will fail with "spec.template.metadata.labels: Invalid value: [...]: 'selector' does not match template 'labels'". Note that the .spec.template.metadata.labels section may declare additional labels.

.spec.template

.spec.template.metadata

.spec.template.metadata.labels

volumeClaimTemplates

volumeClaimTemplates is a list of persistent volume claim specifications, defining persistent volume claims that pods are allowed to reference. The StatefulSet controller is responsible for mapping network identities to claims in a way that maintains the identity of a pod. Every claim in this list must have at least one name-matching volumeMount in one container in the template. The name of the claim is specified as .metadata.name.A claim in this list takes precedence over any volumes in the template, with the same name.

For more details on StatefulSet persistent volume claims see:

StatefulSet Persistent Volume Claim Templates

For more details on persistent claim manifests, see:

Persistent Volume Claim Manifest