美文网首页
K8S-概念

K8S-概念

作者: K8S_Goearth | 来源:发表于2018-11-10 21:47 被阅读0次

    创建PV-持久化存储

    1.创建1台单独的nfs服务器,然后安装nfs服务并配置好/etc/exports文件

    例如:

    [root@nfs ~]# ls /volume/    存放tomcat程序的文件目录

    tomcat_yolink

    [root@nfs ~]# cat /etc/exports    nfs配置文件

    /volume/ 172.16.0.0/24(rw,sync,all_squash)

    [root@nfs ~]# systemctl status nfs  nfs启动状态

    ● nfs-server.service - NFS server and services

      Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)

      Drop-In: /run/systemd/generator/nfs-server.service.d

              └─order-with-mounts.conf

      Active: active (exited) since Sat 2018-11-03 14:32:01 CST; 9h ago

      Process: 13997 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)

      Process: 13995 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)

      Process: 13992 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)

      Process: 14019 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)

      Process: 14013 ExecStartPre=/bin/sh -c /bin/kill -HUP `cat /run/gssproxy.pid` (code=exited, status=0/SUCCESS)

      Process: 14011 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)

    Main PID: 14019 (code=exited, status=0/SUCCESS)

      CGroup: /system.slice/nfs-server.service

    Nov 03 14:32:01 nfs systemd[1]: Starting NFS server and services...

    Nov 03 14:32:01 nfs systemd[1]: Started NFS server and services.

    2.然后在k8s节点,如master,node节点安装nfs程序并挂载nfs服务端的内容

    例如:

    mount -t nfs 172.16.0.10:/volume/ /volume

    以上是nfs安装成功

    3.然后配置持久化存储pv.yaml文件

    例如:

    [root@master1 dockerfile]# cat pv.yaml

    apiVersion: v1

    kind: PersistentVolume

    metadata:

      name: nfs-pv

    spec:

      capacity:

        storage: 20Gi

      volumeMode: Filesystem

      accessModes:

      - ReadWriteMany

      persistentVolumeReclaimPolicy: Recycle

      storageClassName: slow

      nfs:

        path: /volume

        server: 172.16.0.10

    [root@master1 dockerfile]# kubectl get pv

    NAME      CAPACITY  ACCESS MODES  RECLAIM POLICY  STATUS      CLAIM    STORAGECLASS  REASON    AGE

    nfs-pv    20Gi      RWX            Recycle          Available            slow                    6m

    创建PVC

    [root@master1 tomcat-link]# vim tomcat-deployment5.yaml

    apiVersion: v1

    kind: Service

    metadata:

      name: tomcat-nfs

      labels:

        app: tomcat-nfs

    spec:

      type: NodePort

      ports:

      - port: 8080

        targetPort: 8080

        nodePort: 30000

        protocol: TCP

      selector:

      app: tomcat-nfs

    ---

    apiVersion: extensions/v1beta1

    kind: Deployment

    metadata:

      name: tomcat-yolink

      labels:

        app: tomcat-nfs

    spec:

      replicas: 2

      selector:

        matchLabels:

          app: tomcat-nfs

      template:

        metadata:

          labels:

            app: tomcat-nfs

          annotations:

            app: tomcat-clouster

        spec:

          containers:

          - name: tomcat-nfs

            image: 172.16.0.2:5000/docker.io/tomcat

            imagePullPolicy: IfNotPresent

            ports:

            - containerPort: 8080

            volumeMounts:

            - name: tomcatdata

              mountPath: /usr/local/tomcat/webapps/ROOT

          volumes:

            - name: tomcatdata

              hostPath:

                path: /usr/local/www.link.com

                type: DirectoryOrCreate

    相关文章

      网友评论

          本文标题:K8S-概念

          本文链接:https://www.haomeiwen.com/subject/duytfqtx.html