ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

k8s 连接glusterfs 集群使用

2021-08-03 17:35:20  阅读:222  来源: 互联网

标签:name port nginx glusterfs 集群 testnginx k8s ports


准备glusterfs 存储

glusterfs volume 为public,挂载在服务器的/data/public/ 下,创建项目目录projects
mkdir /data/public/projects/

创建单独测试项目数据目录volume-test-nginx 
mkdir /data/public/projects/volume-test-nginx

创建k8s 名称空间 testnginx

kubectl create ns testnginx

准备glusterfs endpoint 配置

{
  "kind": "Endpoints",
  "apiVersion": "v1",
  "metadata": {
    "name": "glusterfs-cluster",
    "namespace": "testnginx"       #指定endpoint 名称空间
  },
  "subsets": [
    {
      "addresses": [
        {
          "ip": "10.65.0.19"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.20"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.21"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.22"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.23"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.24"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.25"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.26"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.65.0.27"
        }
      ],
      "ports": [
        {
          "port": 1000
        }
      ]
    }
  ]
}

准备 glusterfs svc 配置文件

# cat glusterfs-service.json 
{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "glusterfs-cluster",
    "namespace": "testnginx"
  },
  "spec": {
    "ports": [
      {"port": 1000}
    ]
  }
}

准备 glusterfs pv

# cat pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: testnginx
  name: gluster-volume-testnginx
spec:
  capacity:
    storage: 3Gi
  accessModes: ["ReadWriteMany","ReadOnlyMany"]
  glusterfs:
    endpoints: "glusterfs-cluster"
    path: "public/projects/volume-test-nginx" #public 为glusterfs volume,projects/volume-test-nginx 为单独项目路径
    readOnly: false

准备 glusterfs Pvc 配置

# cat pvc.yaml 
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  namespace: testnginx
  name: gluster-volume-testnginx
spec:
  accessModes: ["ReadWriteMany"]
  resources:
    requests:
      storage: 3Gi

准备glusterfs 测试nginx 配置文件

# cat dp.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: testnginx
  namespace: testnginx
  labels:
    app.name: testnginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app.name: testnginx
  template:
    metadata:
      labels:
        app.name: testnginx
    spec:
      containers:
      - name: testnginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: glusterfsvol
          mountPath: "/usr/share/nginx/html"
      volumes:
      - name: glusterfsvol
        persistentVolumeClaim:
          claimName: gluster-volume-testnginx

生成配置文件

kubectl apply  -f glusterfs-endpoints.json
kubectl apply  -f glusterfs-service.json
kubectl apply  -f pv.yaml
kubectl apply  -f pvc.yaml
kubectl apply  -f dp.yaml

查看nginx 数据目录

# kubectl exec -it -n testnginx  testnginx-67f47689d9-zcgrd bash
root@testnginx-67f47689d9-zcgrd:/# cd /usr/share/nginx/html/
root@testnginx-67f47689d9-zcgrd:/usr/share/nginx/html# ls
index.html
root@testnginx-67f47689d9-zcgrd:/usr/share/nginx/html# cat index.html 
111

查看 glusterfs 存储
[root@lgy-storage1 10.65.0.1 /data/public/projects/volume-test-nginx ] 
# cat index.html 
111

标签:name,port,nginx,glusterfs,集群,testnginx,k8s,ports
来源: https://www.cnblogs.com/lixinliang/p/15095246.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有