feat: add local-path-provisioner

pull/1282/head
gjmzj 2023-05-19 21:45:24 +08:00
parent 59d214690e
commit c504e12624
7 changed files with 202 additions and 8 deletions

View File

@ -187,6 +187,12 @@ prom_install: "no"
prom_namespace: "monitor"
prom_chart_ver: "__prom_chart__"
# local-storage (local-path-provisioner) 自动安装
local_path_provisioner_install: "yes"
local_path_provisioner_ver: "__local_path_provisioner__"
# 设置默认本地存储路径
local_path_provisioner_dir: "/opt/local-path-provisioner"
# nfs-provisioner 自动安装
nfs_provisioner_install: "no"
nfs_provisioner_namespace: "kube-system"

2
ezctl
View File

@ -158,6 +158,7 @@ function new() {
dashboardVer=$(grep 'dashboardVer=' ezdown|cut -d'=' -f2)
dashboardMetricsScraperVer=$(grep 'dashboardMetricsScraperVer=' ezdown|cut -d'=' -f2)
metricsVer=$(grep 'metricsVer=' ezdown|cut -d'=' -f2)
localpathProvisionerVer=$(grep 'localpathProvisionerVer=' ezdown|cut -d'=' -f2)
nfsProvisionerVer=$(grep 'nfsProvisionerVer=' ezdown|cut -d'=' -f2)
pauseVer=$(grep 'pauseVer=' ezdown|cut -d'=' -f2)
promChartVer=$(grep 'promChartVer=' ezdown|cut -d'=' -f2)
@ -177,6 +178,7 @@ function new() {
-e "s/__dns_node_cache__/$dnsNodeCacheVer/g" \
-e "s/__dashboard__/$dashboardVer/g" \
-e "s/__dash_metrics__/$dashboardMetricsScraperVer/g" \
-e "s/__local_path_provisioner__/$localpathProvisionerVer/g" \
-e "s/__nfs_provisioner__/$nfsProvisionerVer/g" \
-e "s/__prom_chart__/$promChartVer/g" \
-e "s/__harbor__/$harborVer/g" \

30
ezdown
View File

@ -23,8 +23,8 @@ REGISTRY_MIRROR=CN
# images downloaded by default(with '-D')
calicoVer=v3.24.5
dnsNodeCacheVer=1.22.20
corednsVer=1.9.3
dnsNodeCacheVer=1.22.20
dashboardVer=v2.7.0
dashboardMetricsScraperVer=v1.0.8
metricsVer=v0.6.3
@ -35,6 +35,7 @@ ciliumVer=1.13.2
flannelVer=v0.21.4
kubeRouterVer=v1.5.4
kubeOvnVer=v1.11.5
localpathProvisionerVer=v0.0.24
nfsProvisionerVer=v4.0.2
promChartVer=45.23.0
@ -85,13 +86,14 @@ function usage-down-ext-img(){
echo -e "\033[33mUsage:\033[0m ezdown -X <opt>"
cat <<EOF
available options:
cilium to download images of cilium
flannel to download images of flannel
kube-ovn to download images of kube-ovn
kube-router to download images of kube-router
network-check to download images of network-check
nfs-provisioner to download images of nfs-provisioner
prometheus to download images of prometheus
cilium to download images of cilium
flannel to download images of flannel
kube-ovn to download images of kube-ovn
kube-router to download images of kube-router
local-path-provisioner to download images of local-path-provisioner
network-check to download images of network-check
nfs-provisioner to download images of nfs-provisioner
prometheus to download images of prometheus
examples:
./ezdown -X prometheus
EOF
@ -491,6 +493,18 @@ function get_extra_images() {
docker push "easzlab.io.local:5000/cloudnativelabs/kube-router:$kubeRouterVer"
;;
# local-path-provisioner image
local-path-provisioner)
if [[ ! -f "$imageDir/local-path-provisioner_$localpathProvisionerVer.tar" ]];then
docker pull "rancher/local-path-provisioner:$localpathProvisionerVer" && \
docker save -o "$imageDir/local-path-provisioner_$localpathProvisionerVer.tar" "rancher/local-path-provisioner:$localpathProvisionerVer"
else
docker load -i "$imageDir/local-path-provisioner_$localpathProvisionerVer.tar"
fi
docker tag "rancher/local-path-provisioner:$localpathProvisionerVer" "easzlab.io.local:5000/rancher/local-path-provisioner:$localpathProvisionerVer"
docker push "easzlab.io.local:5000/rancher/local-path-provisioner:$localpathProvisionerVer"
;;
# network-check images
network-check)
if [[ ! -f "$imageDir/network-check.tar" ]];then

View File

@ -0,0 +1,13 @@
- block:
- name: 准备 local-storage 配置目录
file: name={{ cluster_dir }}/yml/local-storage state=directory
- name: 准备 local-storage部署文件
template: src=local-storage/{{ item }}.j2 dest={{ cluster_dir }}/yml/local-storage/{{ item }}
with_items:
- "local-storage.yaml"
- "test-pod.yaml"
- name: 创建 local-storage部署
shell: "{{ base_dir }}/bin/kubectl apply -f {{ cluster_dir }}/yml/local-storage/local-storage.yaml"
when: 'local_path_provisioner_install == "yes"'

View File

@ -18,6 +18,9 @@
- import_tasks: prometheus.yml
when: 'prom_install == "yes"'
- import_tasks: local-storage.yml
when: '"local-path-provisioner" not in pod_info.stdout or CHANGE_CA|bool'
- import_tasks: nfs-provisioner.yml
when: '"nfs-client-provisioner" not in pod_info.stdout or CHANGE_CA|bool'

View File

@ -0,0 +1,125 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: local-path-provisioner-service-account
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: local-path-provisioner-role
rules:
- apiGroups: [ "" ]
resources: [ "nodes", "persistentvolumeclaims", "configmaps" ]
verbs: [ "get", "list", "watch" ]
- apiGroups: [ "" ]
resources: [ "endpoints", "persistentvolumes", "pods" ]
verbs: [ "*" ]
- apiGroups: [ "" ]
resources: [ "events" ]
verbs: [ "create", "patch" ]
- apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "get", "list", "watch" ]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: local-path-provisioner-bind
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: local-path-provisioner-role
subjects:
- kind: ServiceAccount
name: local-path-provisioner-service-account
namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-path-provisioner
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: local-path-provisioner
template:
metadata:
labels:
app: local-path-provisioner
spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: easzlab.io.local:5000/rancher/local-path-provisioner:{{ local_path_provisioner_ver }}
imagePullPolicy: IfNotPresent
command:
- local-path-provisioner
- --debug
- start
- --config
- /etc/config/config.json
volumeMounts:
- name: config-volume
mountPath: /etc/config/
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: config-volume
configMap:
name: local-path-config
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-path
provisioner: rancher.io/local-path
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
---
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: kube-system
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["{{ local_path_provisioner_dir }}"]
}
]
}
setup: |-
#!/bin/sh
set -eu
mkdir -m 0777 -p "$VOL_DIR"
teardown: |-
#!/bin/sh
set -eu
rm -rf "$VOL_DIR"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: easzlab.io.local:5000/rancher/local-path-provisioner:{{ local_path_provisioner_ver }}
imagePullPolicy: IfNotPresent

View File

@ -0,0 +1,31 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-path-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 128Mi
---
apiVersion: v1
kind: Pod
metadata:
name: volume-test
spec:
containers:
- name: volume-test
image: nginx:stable-alpine
imagePullPolicy: IfNotPresent
volumeMounts:
- name: volv
mountPath: /data
ports:
- containerPort: 80
volumes:
- name: volv
persistentVolumeClaim:
claimName: local-path-pvc