在k8s上部署一些持久化数据的时候,nfs是非常方便的、便宜的、高效的一种存储介质。

1.节点上需要挂在nfs,所以需要安装nfs相关系统组件。在k8s集群node系统上进行安装。

apt-get install nfs-common

or

yum install nfs-utils

2.定义pv和pvc请求。

apiVersion: v1

kind: PersistentVolume

metadata:

name: pv-nfs-pv

labels:

type: local

spec:

storageClassName: manual

capacity:

storage: 1Gi

accessModes:

- ReadWriteMany

nfs:

path: "/mnt/nfs/k8s/k8s/"

server: 192.168.1.18

---

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: pvc-nfs-pv

spec:

storageClassName: manual

accessModes:

- ReadWriteMany

resources:

requests:

storage: 500Mi

---

apiVersion: apps/v1

kind: Deployment

metadata:

name: pvc-nginx

spec:

selector:

matchLabels:

app: pvc-nginx

template:

metadata:

labels:

app: pvc-nginx

spec:

containers:

- name: pvc-nginx

image: nginx:latest

resources:

limits:

memory: "128Mi"

cpu: "500m"

ports:

- containerPort: 80

volumeMounts:

- name: pvc

mountPath: /usr/share/nginx/html

volumes:

- name: pvc

persistentVolumeClaim:

claimName: pvc-nfs-pv

---

apiVersion: v1

kind: Service

metadata:

name: pvc-nginx

spec:

selector:

app: pvc-nginx

ports:

- port: 80

targetPort: 80

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐