文章参考
https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
前言:本文旨在实验ICP nginx使用gpfs存储作为默认存储。/gpfs为gpfs软件挂载点
[root@master data]# df -h | grep /gpfs
文章参考:Redhat 7.4 安装Spectrum for Scale 5.0.2
1.创建nginx数据目录
[root@master nginx]# mkdir -p /gpfs/nginx/data/
[root@master nginx]# touch index.html
[root@master nginx]# echo 'Hello from Kubernetes storage' > /gpfs/nginx/data/index.html
2.下载nginx镜像
[root@master nginx]# docker pull nginx
3.上传nginx镜像至ICP仓库
[root@master nginx]#docker tag dbfc48660aeb mycluster.icp:8500/default/nginx:v1.0
[root@master nginx]#docker push mycluster.icp:8500/default/nginx:v1.0
4.验证登录ICP
[root@master nginx]# cloudctl login -a https://mycluster.icp:8443 --skip-ssl-validation
5.创建pvc和pv
[root@master nginx]# kubectl create -f nginx-pvc.yaml
[root@master nginx]# kubectl create -f nginx-pv.yaml
[root@master nginx]# kubectl get pv
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gpfsclaim
namespace: default
spec:
accessModes:
apiVersion: v1
kind: PersistentVolume
metadata:
name: gpfsstorage
namespace: default
labels:
storage: gpfs
spec:
capacity:
storage: 2Gi
hostPath:
path: "/gpfs/nginx/data"
accessModes:
6.创建nginx deployment
[root@master nginx]# kubectl create -f nginx-deployment.yaml
kind: Pod
apiVersion: v1
metadata:
name: nginx-pv-pod
spec:
volumes:
- name: nginx-pv-storage
persistentVolumeClaim:
claimName: gpfsclaim
containers:
- name: nginx-pv-container
image: mycluster.icp:8500/default/nginx:v2.0
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/opt/bitnami/nginx/html"
name: nginx-pv-storage
7.查看nginx pod
[root@master nginx]# kubectl get pods --namespace=default | grep nginx-pv-pod
[root@master nginx]# kubectl get pod nginx-pv-pod
8.使用shell登录到容器内部
[root@master nginx]# kubectl exec -it nginx-pv-pod -- /bin/bash
9.查看index.html内容,可以看到在nginx-pv-pod里面内容是Hello from Kubernetes storage
I have no name!@nginx-pv-pod:/$ cd /opt/bitnami/nginx/html
I have no name!@nginx-pv-pod:/opt/bitnami/nginx/html$ cat index.html
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞3
添加新评论0 条评论