Kubernetes StatefulSet Manifest: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(25 intermediate revisions by the same user not shown)
Line 14: Line 14:
   replicas: 1
   replicas: 1
   serviceName: postgresql-headless
   serviceName: postgresql-headless
   selector:
   [[#.spec.selector|selector]]:
     matchLabels:
     <span id='spec_selector_matchLabels'></span>[[#.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 21: Line 21:
   updateStrategy:  
   updateStrategy:  
     type: RollingUpdate
     type: RollingUpdate
   <span id='template_metadata'></span>template:
   <span id='template_metadata'></span>[[#.spec.template|template]]:
     metadata:
     metadata:
       name: postgresql
       name: postgresql
       labels:
       <span id='spec_template_metadata_labels'></span>[[#.spec.template.metadata.labels|labels]]: <font color=teal># this section may declare additional labels to [[#spec_selector_matchLabels|.spec.selector.matchLabels]]</font>
         app: postgresql
         app: postgresql
         role: master
         role: master
        color: blue
     spec:
     spec:
       <span id='template_containers'></span>containers:
       <span id='template_containers'></span>containers:
Line 38: Line 39:
       terminationGracePeriodSeconds: ...
       terminationGracePeriodSeconds: ...
   [[#volumeClaimTemplates|volumeClaimTemplates]]:
   [[#volumeClaimTemplates|volumeClaimTemplates]]:
    <font color=teal># ''for details see [[Kubernetes_Persistent_Volume_Claim_Manifest|Persistent Volume Claim Manifest]]''</font>
     - metadata:
     - metadata:
         <span id='name_template'></span>[[#Volume_Claim_Name|name]]: data
         <span id='name_template'></span>[[#Volume_Claim_Name|name]]: data
       spec:
       spec:
         volumeMode: Filesystem
         [[Kubernetes_Persistent_Volume_Claim_Manifest#volumeMode|volumeMode]]: Filesystem
         accessModes:
         <font color=teal># Optionally a storage class can be specified, otherwise the default storage class will be used</font>
        # storageClassName: manual-local-storage
        [[Kubernetes_Persistent_Volume_Claim_Manifest#accessModes|accessModes]]:
           - ReadWriteOnce
           - ReadWriteOnce
         resources:
         [[Kubernetes_Persistent_Volume_Claim_Manifest#resources|resources]]:
           requests:
           [[Kubernetes_Persistent_Volume_Claim_Manifest#requests|requests]]:
             storage: 8Gi
             [[Kubernetes_Persistent_Volume_Claim_Manifest#storage|storage]]: 8Gi


=.spec Elements=
=.spec Elements=
==template==
==.spec.selector==
===.spec.selector.matchLabels===
{{Warn|The labels declared in this section must exist also in the [[#.spec.template.metadata.labels|.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|.spec.template.metadata.labels]] section may declare additional labels.}}
 
When the corresponding persistent volume claims are created, they will be automatically get all the labels declared in this section. For more details, see: {{Internal|Kubernetes_StatefulSet#Labels_on_a_Persistent_Volume_Claim_created_from_the_Persistent_Volume_Claim_Template|Labels on a Persistent Volume Claim created from the Persistent Volume Claim Template}}
 
==.spec.template==
 
===.spec.template.metadata===
 
====.spec.template.metadata.labels====
 
==volumeClaimTemplates==
==volumeClaimTemplates==


"volumeClaimTemplates" is a list of [[Kubernetes_Persistent_Volume_Claim_Manifest|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. <span id='Volume_Claim_Name'></span>Every claim in this list must have at least one name-matching volumeMount in one [[#template_containers|container]] in the [[#template_metadata|template]]. The name of the claim is specified as [[#name_template|.metadata.name]].A claim in this list takes precedence over any volumes in the template, with the same name. For more details on persistent claim manifests, see: {{Internal|Kubernetes Persistent Volume Claim Manifest|Persistent Volume Claim Manifest}}
<code>volumeClaimTemplates</code> is a list of [[Kubernetes_Persistent_Volume_Claim_Manifest|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. <span id='Volume_Claim_Name'></span>Every claim in this list must have at least one name-matching volumeMount in one [[#template_containers|container]] in the [[#template_metadata|template]]. The name of the claim is specified as [[#name_template|.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: {{Internal|Kubernetes_StatefulSet#Persistent_Volume_Claim_Template|StatefulSet Persistent Volume Claim Templates}}
 
For more details on persistent claim manifests, see: {{Internal|Kubernetes Persistent Volume Claim Manifest|Persistent Volume Claim Manifest}}

Latest revision as of 20:47, 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: # this section may declare additional labels to .spec.selector.matchLabels
        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.

When the corresponding persistent volume claims are created, they will be automatically get all the labels declared in this section. For more details, see:

Labels on a Persistent Volume Claim created from the Persistent Volume Claim Template

.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