Kubernetes Volume NFS

使用NFS网络文件系统提供的共享存储目录数据时,我们需要在系统中部署一个NFS。定义NFS类型的Volume

##创建namespaces

apiVersion: v1
kind: Namespace
metadata:
   name: test
   labels:
     name: test

##创建nfs-PV
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
  namespace: test
  labels:
    pv: nfs-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain

  nfs:      ##### NFS 配置
    path: /data/nginx   # 挂载目录 
    server: 192.168.22.8    # NFS Server

##创建 NFS-pvc

---
kind: PersistentVolumelaim
apiVersion: v1
metadata:
  name: nfs-pvc
  namespace: test
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  selector:
    matchLabels:
      pv: nfs-pv

## 部署应用Nginx

---

apiVersion: v1
kind: Replicationontroller
metadata:
  name: nginx-test
  labels:
    name: nginx-test
  namespace: test
spec:
  replicas: 2
  selector:
    name: nginx-test
  template:
    metadata:
      labels: 
       name: nginx-test
    spec:
      containers:
      - name: nginx-test
        image: docker.io/nginx
        volumeMounts:
        - mountPath: /usr/share/nginx/html
          name: nginx-data
        ports:
        - containerPort: 80
      volumes:
      - name: nginx-data
        persistentVolumelaim:
          claimName: nfs-pvc

##创建Service

---

apiVersion: v1
kind: Service
metadata:
  name: nginx-test
  labels: 
   name: nginx-test
  namespace: test
spec:
  type: NodePort
  ports:
  - port: 80
    protocol: P
    targetPort: 80
    name: http
    nodePort: 20080
  selector:
    name: nginx-test

相关参考 K8s ceph 介绍 K8s企业实践使用storageclass实现动态存储

Copyright © i4t.com 2019 all right reserved,powered by Gitbook该文件修订时间: 2019-04-26 21:31:27

results matching ""

    No results matching ""