kubernets host PersistentVolume 测试
因为yaml 格式的问题 ,我修改为了json
创建 pv
pv.json
{
"kind": "PersistentVolume",
"apiVersion": "v1",
"metadata": {
"name": "mydemo-pv",
"labels": {
"type": "local-dalong"
}
},
"spec": {
"capacity": {
"storage": "1Gi"
},
"accessModes": [
"ReadWriteOnce"
],
"hostPath": {
"path": "/Users/dalong/pvapp"
}
}
}
kubectl apply -f pv.json
创建pvc
pvc.json
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "myclaim"
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"volumeMode": "Filesystem",
"resources": {
"requests": {
"storage": "500Mi"
}
},
"selector": {
"matchLabels": {
"type": "local-dalong"
}
}
}
}
kubectl apply -f pvc.json
使用pvc
app.yml
apiVersion: v1
kind: Namespace
metadata:
name: nginx-app
labels:
name: nginxs
---
apiVersion: v1
kind: ReplicationController
metadata:
name: mynignx
spec:
replicas: 1
selector:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
readinessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 15
periodSeconds: 20
volumeMounts:
- mountPath: /usr/share/nginx/html
name: git-volume
volumes:
- name: git-volume
persistentVolumeClaim:
claimName: myclaim
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
name: nginx
ports:
- name: http
port: 80
protocol: TCP
nodePort: 31604
type: NodePort
结果
参考资料
https://kubernetes.io/docs/concepts/storage/
https://github.com/rongfengliang/k8s-host-pvdemo