Kubernetes Cloud Native 实践 ( 三 ) NFS/PV/PVC
2023-06-13 20:39:32 375
全文目录
Kubernetes Cloud Native 实践 ( 一 ) 安装
Kubernetes Cloud Native 实践 ( 二 ) 简单使用
Kubernetes Cloud Native 实践 ( 三 ) NFS/PV/PVC
Kubernetes Cloud Native 实践 ( 四 ) 中间件上云
Kubernetes Cloud Native 实践 ( 五 ) 应用上云
Kubernetes Cloud Native 实践 ( 六 ) 集成ELK日志平台
Kubernetes Cloud Native 实践 ( 七 ) 应用监控
Kubernetes Cloud Native 实践 ( 八 ) CICD集成
Kubernetes Cloud Native 实践 ( 九 ) 运维管理
Kubernetes Cloud Native 实践 ( 十 ) 相关问题
Kubernetes Cloud Native 实践 ( 十一 ) 运行截图
NFS/PV/PVC
apt install nfs-common
所有节点- 主节点
- 从节点
- 自动创建pv, 依次kubectl apply -f xxx.yaml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: Role
name: leader-locking-nfs-client-provisioner
apiGroup: rbac.authorization.k8s.io
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: nfs-client-provisioner
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client-provisioner
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccount: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: easzlab/nfs-subdir-external-provisioner:v4.0.1
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: fuseim.pri/ifs
- name: NFS_SERVER
value: 192.168.222.129
- name: NFS_PATH
value: /nfs
volumes:
- name: nfs-client-root
nfs:
server: 192.168.222.129
path: /nfs
- 测试一下, kubectl apply -f xxx.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
annotations:
volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
- 对应用进行扩容缩容删除, 主机的nfs数据仍然存在