k8s使用glusterfs存储系统

最近部署了k8s,默认使用的主机存储。主机/目录默认空间较小,并且部分容器对磁盘io要求较高。遂搭建glusterfs文件系统,并配置给k8s使用。
glusterfs搭建步骤见 https://www.cnblogs.com/tangshow/p/15930784.html

环境

cetons7已部署glusterfs主机三台(k8s也位于这三台上)
master1(node01) 192.168.2.134
master2(node01) 192.168.2.80
cli    (nfs)    192.168.2.131

注意:

默认情况下 Endpoints、pv 、pvc 都在default空间 ,在default使用glusterfs时不用指定空间
当需要在其他空间使用glusterfs时,需要创建Endpoints、pv 、pvc时都指定空间,例:
  metadata:
    namespace: kube-system

1 创建Endpoints 和对应的service

kubectl apply -f glusterfs-cluster.yaml

glusterfs-cluster.yam内容如下:

apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: 192.168.2.134
  ports:
  - port: 49152
- addresses:
  - ip: 192.168.2.131
  ports:
  - port: 49152
- addresses:
  - ip: 192.168.2.80
  ports:
  - port: 49152

---
apiVersion: v1
kind: Service
metadata:
  name: glusterfs-cluster
spec:
  ports:
  - port: 49152	

2 创建容器指定使用gluster做存储

kubectl apply -f nginx_test.yaml
# 为方便测试,此方法没有使用pv/pvc 直接指定"endpoints: glusterfs-cluster"


nginx_test.yaml内容如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-test
spec:
  replicas: 1
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - name: storage001
              mountPath: "/usr/share/nginx/html"
      volumes:
      - name: storage001
        glusterfs:
          endpoints: glusterfs-cluster
          path: models
          readOnly: false
posted @ 2022-01-26 15:34  tangshow  阅读(438)  评论(0编辑  收藏  举报