码迷,mamicode.com
首页 > 其他好文 > 详细

k8s PersistentVolume hostpath 简单使用

时间:2018-06-28 12:07:51      阅读:827      评论:0      收藏:0      [点我收藏+]

标签:local   tcp   dem   use   resources   IV   kubectl   service   image   

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 简单使用

标签:local   tcp   dem   use   resources   IV   kubectl   service   image   

原文地址:https://www.cnblogs.com/rongfengliang/p/9237832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!