Local PV是从kuberntes 1.10开始引入,本质目的是为了解决hostPath的缺陷。经过PV控制器与Scheduler的结合,会对local PV作针对性的逻辑处理,从而,让Pod在屡次调度时,可以调度到同一个Node上。node
此次,测试了一下将local PV挂载到一个httpd的应用上。docker
要注意,pvc是按namespace提供的。还有,matchExpressions做匹配的主机名规则。apache
一,local-pv.yamlapi
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-pv-sda
spec:
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local: path: /data/pv
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- spark-docker
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: local-pvc-sda
namespace: in-demo
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 10Gi
二,httpd.yamlapp
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: httpd
namespace: in-demo
spec:
replicas: 2
revisionHistoryLimit: 5
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: httpd-dm
spec:
terminationGracePeriodSeconds: 60
restartPolicy: Always
containers:
- name: httpd
image: httpd:alpine
imagePullPolicy: IfNotPresent
volumeMounts:
- name: storage-localpv
mountPath: "/usr/local/apache2/htdocs"
volumes:
- name: storage-localpv
persistentVolumeClaim: claimName: local-pvc-sda
---
apiVersion: v1
kind: Service
metadata:
name: httpd-svc
namespace: in-demo
spec:
ports:
- name: http-port
port: 80
targetPort: 80
selector:
app: httpd-dm