微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

k8s 连接glusterfs 集群使用

准备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
@H_502_30@准备 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐