apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
namespace: data-system
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: Service
metadata:
name: nginx-test
spec:
selector:
app: nginx-test
ports:
- protocol: TCP
port: 80
targetPort: 8080
name: web
clusterIP: None
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nginx-test
labels:
app: nginx-test
spec:
replicas: 1
serviceName: nginx-test
persistentVolumeClaimRetentionPolicy:
whenDeleted: Delete
selector:
matchLabels:
app: nginx-test
template:
metadata:
name: nginx-test
labels:
app: nginx-test
spec:
containers:
- name: nginx-test
image: wener/nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: web
volumeMounts:
- mountPath: /var/www/html
name: data
restartPolicy: Always
volumeClaimTemplates:
- metadata:
name: data
spec:
storageClassName: local-storage
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
selector:
matchLabels:
local: pv-2
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv-1
labels:
local: pv-2
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /tmp/pv-1
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- svr-1
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv-2
labels:
local: pv-2
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /tmp/pv-2
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- svr-1