mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Merge pull request #42436 from vmware/add-stateful-set-example.kerneltime
Automatic merge from submit-queue (batch tested with PRs 42237, 42297, 42279, 42436, 42551) Add example for how to use vSphere volumes in Stateful Sets **What this PR does / why we need it**: Examples yaml for using vSphere volumes in stateful sets. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note ```
This commit is contained in:
commit
c2286b8c1c
@ -5,6 +5,7 @@
|
|||||||
- [Volumes](#volumes)
|
- [Volumes](#volumes)
|
||||||
- [Persistent Volumes](#persistent-volumes)
|
- [Persistent Volumes](#persistent-volumes)
|
||||||
- [Storage Class](#storage-class)
|
- [Storage Class](#storage-class)
|
||||||
|
- [Stateful Set](#stateful-set)
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@ -352,7 +353,80 @@
|
|||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
pvpod 1/1 Running 0 48m
|
pvpod 1/1 Running 0 48m
|
||||||
```
|
```
|
||||||
|
### Stateful Set
|
||||||
|
|
||||||
|
vSphere volumes can be consumed by Stateful Sets.
|
||||||
|
|
||||||
|
1. Create a storage class that will be used by the ```volumeClaimTemplates``` of a Stateful Set.
|
||||||
|
|
||||||
|
See example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kind: StorageClass
|
||||||
|
apiVersion: storage.k8s.io/v1beta1
|
||||||
|
metadata:
|
||||||
|
name: thin-disk
|
||||||
|
provisioner: kubernetes.io/vsphere-volume
|
||||||
|
parameters:
|
||||||
|
diskformat: thin
|
||||||
|
```
|
||||||
|
|
||||||
|
[Download example](simple-storageclass.yaml)
|
||||||
|
|
||||||
|
2. Create a Stateful set that consumes storage from the Storage Class created.
|
||||||
|
|
||||||
|
See example:
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
labels:
|
||||||
|
app: nginx
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
name: web
|
||||||
|
clusterIP: None
|
||||||
|
selector:
|
||||||
|
app: nginx
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: web
|
||||||
|
spec:
|
||||||
|
serviceName: "nginx"
|
||||||
|
replicas: 14
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: nginx
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: gcr.io/google_containers/nginx-slim:0.8
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: web
|
||||||
|
volumeMounts:
|
||||||
|
- name: www
|
||||||
|
mountPath: /usr/share/nginx/html
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: www
|
||||||
|
annotations:
|
||||||
|
volume.beta.kubernetes.io/storage-class: thin-disk
|
||||||
|
spec:
|
||||||
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 1Gi
|
||||||
|
```
|
||||||
|
This will create Persistent Volume Claims for each replica and provision a volume for each claim if an existing volume could be bound to the claim.
|
||||||
|
|
||||||
|
[Download example](simple-statefulset.yaml)
|
||||||
|
|
||||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||||
[]()
|
[]()
|
||||||
|
46
examples/volumes/vsphere/simple-statefulset.yaml
Normal file
46
examples/volumes/vsphere/simple-statefulset.yaml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
labels:
|
||||||
|
app: nginx
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
name: web
|
||||||
|
clusterIP: None
|
||||||
|
selector:
|
||||||
|
app: nginx
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: web
|
||||||
|
spec:
|
||||||
|
serviceName: "nginx"
|
||||||
|
replicas: 14
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: nginx
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: gcr.io/google_containers/nginx-slim:0.8
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: web
|
||||||
|
volumeMounts:
|
||||||
|
- name: www
|
||||||
|
mountPath: /usr/share/nginx/html
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: www
|
||||||
|
annotations:
|
||||||
|
volume.beta.kubernetes.io/storage-class: thin-disk
|
||||||
|
spec:
|
||||||
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 1Gi
|
7
examples/volumes/vsphere/simple-storageclass.yaml
Normal file
7
examples/volumes/vsphere/simple-storageclass.yaml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
kind: StorageClass
|
||||||
|
apiVersion: storage.k8s.io/v1beta1
|
||||||
|
metadata:
|
||||||
|
name: thin-disk
|
||||||
|
provisioner: kubernetes.io/vsphere-volume
|
||||||
|
parameters:
|
||||||
|
diskformat: thin
|
Loading…
Reference in New Issue
Block a user