1. 查看集群里的persistent volume
kubectl get pv
2. 创建集群角色cluster role
kubectl create clusterrole pv-reader --verb=get,list --resource=persistentvolumes
3. 创建集群角色绑定cluster role binding
kubectl create clusterrolebinding pv-test --clusterrole=pv-reader --serviceaccount=web:default
4. 创建一个pod
(1)创建连接,并curl一个地址。创建一个yaml文件,内容写为:
apiVersion: v1
kind: Pod
metadata:
name: curlpod
namespace: web
spec:
containers:
- image: tutum/curl
command: ["sleep", "9999999"]
name: main
- image: linuxacademycontent/kubectl-proxy
name: proxy
restartPolicy: Always
(2)执行步骤(1)中的yaml文件,创建pod
kubectl apply -f curlpod.yaml
5. 访问pod中的PV(persistent volumes )
kubectl exec -it curlpod -n web -- sh
curl localhost:8001/api/v1/persistentvolumes 验证是否能访问