文档章节

k8s之持续化存储卷nfs动态绑定

o
 osc_3byfn0lk
发布于 07/01 09:50
字数 634
阅读 27
收藏 0

精选30+云产品,助力企业轻松上云!>>>

安装nfs服务这里安装在slave2一个节点上

[root@k8s-slave2 ~]# yum -y install nfs-utils rpcbind
[root@k8s-slave2 ~]# cat /etc/exports
/data/nfs/ *(insecure,rw,async,no_root_squash)

[root@k8s-slave2 ~]# chmod 777 /data/nfs/

先启动rpcbind服务在启动nfs
[root@k8s-slave2 ~]# systemctl start rpcbind
[root@k8s-slave2 ~]# systemctl start nfs
主节点验证
[root@k8s-master ~]# showmount -e 192.168.60.102
Export list for 192.168.60.102:
/data/nfs *





下载外部存储卷的供应器代码

git clone https://github.com/kubernetes-incubator/external-storage
下载完成进入external-storage目录
[root@k8s-master deploy]# pwd
/root/external-storage/nfs-client/deploy


创建storageclass
[root@k8s-master deploy]# kubectl apply -f class.yaml
[root@k8s-master deploy]# kubectl apply -f rbac.yaml

修改deloyment.yaml中的nfs挂载参数

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: default
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: 192.168.60.102
            - name: NFS_PATH
              value: /data/nfs
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.60.102
            path: /data/nfs

[root@k8s-master deploy]# kubectl apply -f deployment.yaml
查看 storageclass
[root@k8s-master deploy]# kubectl get storageclass
NAME PROVISIONER AGE
managed-nfs-storage fuseim.pri/ifs 18h
也可以通过dashboard查看
k8s之持续化存储卷nfs动态绑定
生成资源类型:
[root@k8s-master deploy]# kubectl apply -f test-claim.yaml
生成一个测试pod:
[root@k8s-master deploy]# kubectl apply -f test-pod.yaml
查看服务,也可通过dashborad查看,这里不做展示下面通过一个mysql实例演示一下
[root@k8s-master deploy]# kubectl get pv
[root@k8s-master deploy]# kubectl get pvc












mysql pod动态存储的生成

这里nodeport端口还是mysql的3306 kubernets默认映射端口3000端口起步
这里修改kube-api参数
vim /etc/kubernetes/manifests/kube-apiserver.yaml
添加 - --service-node-port-range=1-65535
k8s之持续化存储卷nfs动态绑定
重启服务
systemctl restart kubelet





[root@k8s-master mysql]# cat mysql-claim.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-claim
  annotations:
    volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" 
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

[root@k8s-master mysql]# cat mysql-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: default
  labels:
    k8s-app: mysql
spec:
  replicas: 1
  selector: 
    matchLabels:
      k8s-app: mysql
  template:
    metadata:
      labels:
        k8s-app: mysql
    spec:
      nodeName: k8s-slave1
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/mysql5-7/mysql5-7:5.7
        name: mysql
        imagePullPolicy: Always
        env:
          - name: MYSQL_ROOT_PASSWORD
            value: "123.com" 
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: nfs-pv
          mountPath: /var/lib/mysql
      volumes:
        - name: nfs-pv
          persistentVolumeClaim:
            claimName: mysql-claim

[root@k8s-master mysql]# cat nodeport.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  selector:
    k8s-app: mysql
  ports:
  - nodePort: 3306
    protocol: TCP
    port: 3306
    targetPort: 3306
  type: NodePort

[root@k8s-master mysql]# cat service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  type: NodePort

  ports:

  - port: 3306

    protocol: TCP

    targetPort: 3306

    name: http

    nodePort: 3306

  selector:
    k8s-app: mysql

依次生成:
[root@k8s-master mysql]# kubectl apply -f mysql-claim.yaml
[root@k8s-master mysql]# kubectl apply -f mysql-deployment.yaml
[root@k8s-master mysql]# kubectl apply -f nodeport.yaml
[root@k8s-master mysql]# kubectl apply -f service.yaml
查看服务
[root@k8s-master mysql]# kubectl get pv





NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                 STORAGECLASS          REASON   AGE
pvc-f9c4bb26-f788-4e08-820b-d128d3921604   10Gi       RWO            Delete           Bound    default/mysql-claim   managed-nfs-storage            18h

[root@k8s-master mysql]# kubectl get pvc

NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE
mysql-claim   Bound    pvc-f9c4bb26-f788-4e08-820b-d128d3921604   10Gi       RWO            managed-nfs-storage   18h

现在到nfs服务端查看:
k8s之持续化存储卷nfs动态绑定
本地验证一下:
k8s之持续化存储卷nfs动态绑定


o
粉丝 0
博文 61
码字总数 0
作品 0
私信 提问
加载中
请先登录后再评论。

暂无文章

DateTime2与SQL Server中的DateTime - DateTime2 vs DateTime in SQL Server

问题: Which one: 哪一个: datetime datetime2 is the recommended way to store date and time in SQL Server 2008+? 是在SQL Server 2008+中存储日期和时间的推荐方法吗? I'm aware of......

富含淀粉
18分钟前
6
0
Linux 文件打开过多 (Too many open files)

如图是程序运行了一段时间后抛出来的一个bug, 刚开始看这个bug的时候各种网上找答案, 无外乎教你怎么改ulimit(就是linux最大打开文件数), 当然不是说改这个没有用, 作为程序开发者来说, 如果...

onedotdot
19分钟前
20
0
ZStack实践汇|ZStack与行云管家对接实践ZStack与行云管家对接实践

一、ZStack与行云管家概述 大道至简·极速部署,ZStack致力于产品化私有云和混合云。 ZStack是一家坚持自主创新、专注产品化的云计算公司,以“降低企业上云门槛、让每一家企业都拥有自己的云...

ZStack社区版
24分钟前
7
0
switch linux mint 20 apt repository to tsinghua' mirrors

edit file /etc/apt/sources.list.d/cat official-package-repositories.list lwk@qwfys:/etc/apt/sources.list.d$ lltotal 12drwxr-xr-x 2 root root 4096 Jul 5 20:01 ./drwxr-xr-x 7 ......

qwfys
44分钟前
7
0
面试系列之C++的对象布局【建议收藏】

我们都知道C++多态是通过虚函数表来实现的,那具体是什么样的大家清楚吗?开篇依旧提出来几个问题: 普通类对象是什么布局? 带虚函数的类对象是什么布局? 单继承下不含有覆盖函数的类对象是...

伊牙牙嘿哈哈
今天
17
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部