hbhe0316
作者hbhe0316·2019-01-08 10:48
数据库管理员·IBM

ICP创建有状态nginx

字数 2291阅读 1576评论 0赞 3

文章参考
https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
前言:本文旨在实验ICP nginx使用gpfs存储作为默认存储。/gpfs为gpfs软件挂载点
[root@master data]# df -h | grep /gpfs
mk61ubfj84

mk61ubfj84

文章参考: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
21mvliyloqx

21mvliyloqx

4.验证登录ICP
[root@master nginx]# cloudctl login -a https://mycluster.icp:8443 --skip-ssl-validation
sc5ueimtln

sc5ueimtln

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

[root@master nginx]# kubectl get pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gpfsclaim
namespace: default
spec:
accessModes:

  • ReadWriteMany
    selector:
    matchLabels:
    storage: gpfs
    resources:
    requests:
    storage: 1Gi
    volumeName: gpfsstorage

apiVersion: v1
kind: PersistentVolume
metadata:
name: gpfsstorage
namespace: default
labels:

storage: gpfs      

spec:
capacity:

storage: 2Gi

hostPath:

path: "/gpfs/nginx/data"

accessModes:

  • ReadWriteMany

0immv3g3lf2k

0immv3g3lf2k

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 

etu5s7707ps

etu5s7707ps

7.查看nginx pod
[root@master nginx]# kubectl get pods --namespace=default | grep nginx-pv-pod
[root@master nginx]# kubectl get pod nginx-pv-pod
npqd6hmbox

npqd6hmbox

ycdifcp2fr
ycdifcp2fr

8.使用shell登录到容器内部
[root@master nginx]# kubectl exec -it nginx-pv-pod -- /bin/bash
lykrtbk8jon

lykrtbk8jon

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
n79t7zo2qm

n79t7zo2qm

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

3

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广