部署local-path-storage
环境:
os:Centos 7
k8s:1个master 2个nodes
以下操作都是在master节点上完成
1.下载配置文件
cd /soft
wget https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.30/deploy/local-path-storage.yaml
2.修改镜像文件local-path-storage.yaml
因为无法访问国外的镜像,需要想办法把镜像下载到自己的私人镜像,所以需要修改yaml配置文件
cd /soft
vi local-path-storage.yaml
image: local-path-provisioner:v0.0.30
修改为:
image: registry.cn-shenzhen.aliyuncs.com/hxlk8s/local-path-provisioner:v0.0.30
image: busybox
修改为:
image: registry.cn-shenzhen.aliyuncs.com/hxlk8s/busybox:1.32
3.部署
kubectl apply -f local-path-storage.yaml
4.查看
[root@master soft]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
local-path rancher.io/local-path Delete WaitForFirstConsumer false 20s
[root@master soft]# kubectl -n local-path-storage get pod
NAME READY STATUS RESTARTS AGE
local-path-provisioner-7cb576c467-q9tmh 1/1 Running 0 2m9s
查看日志:
kubectl -n local-path-storage logs -f -l app=local-path-provisioner
5.测试验证-创建pvc和pod
cd /soft
wget https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pvc/pvc.yaml
wget https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod/pod.yaml
修改 pod.yaml 将镜像修改为
nginx:stable-alpine
修改为:
registry.cn-shenzhen.aliyuncs.com/hxlk8s/nginx:stable-alpine
然后执行:
kubectl create -f pvc.yaml
kubectl create -f pod.yaml
[root@master soft]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-1019f191-cc98-4c51-bce0-ec063be5ce10 128Mi RWO Delete Bound default/local-path-pvc local-path 13m
[root@master soft]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
local-path-pvc Bound pvc-1019f191-cc98-4c51-bce0-ec063be5ce10 128Mi RWO local-path 14m
[root@master soft]#
[root@master soft]# kubectl get pod
NAME READY STATUS RESTARTS AGE
volume-test 1/1 Running 0 14m
生成文件
[root@master soft]# kubectl exec volume-test -- sh -c "echo local-path-test > /data/test"
让删除pod
cd soft
kubectl delete -f pod.yaml
然后重建
kubectl create -f pod.yaml
查看内容:
[root@master soft]# kubectl exec volume-test -- sh -c "cat /data/test"
local-path-test
6.删除:
cd /soft
kubectl delete -f pod.yaml
kubectl delete -f pvc.yaml
kubectl delete -f local-path-storage.yaml