k8s PersistentVolume hostpath 简单使用
Posted rongfengliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s PersistentVolume hostpath 简单使用相关的知识,希望对你有一定的参考价值。
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
以上是关于k8s PersistentVolume hostpath 简单使用的主要内容,如果未能解决你的问题,请参考以下文章