Skip to content

Commit

Permalink
Merge pull request #16 from Kuber-2024-04OTUS/kubernetes-csi
Browse files Browse the repository at this point in the history
Kubernetes csi
  • Loading branch information
alexeev79 authored Sep 16, 2024
2 parents 0bb856c + f8d09ea commit d33a244
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 0 deletions.
122 changes: 122 additions & 0 deletions kubernetes-csi/csi-s3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: csi-s3
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-s3
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-s3
subjects:
- kind: ServiceAccount
name: csi-s3
namespace: kube-system
roleRef:
kind: ClusterRole
name: csi-s3
apiGroup: rbac.authorization.k8s.io
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: csi-s3
namespace: kube-system
spec:
selector:
matchLabels:
app: csi-s3
template:
metadata:
labels:
app: csi-s3
spec:
tolerations:
- key: CriticalAddonsOnly
operator: Exists
- operator: Exists
effect: NoExecute
tolerationSeconds: 300
serviceAccount: csi-s3
containers:
- name: driver-registrar
image: quay.io/k8scsi/csi-node-driver-registrar:v1.2.0
args:
- "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)"
- "--v=4"
- "--csi-address=$(ADDRESS)"
env:
- name: ADDRESS
value: /csi/csi.sock
- name: DRIVER_REG_SOCK_PATH
value: /var/lib/kubelet/plugins/ru.yandex.s3.csi/csi.sock
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: plugin-dir
mountPath: /csi
- name: registration-dir
mountPath: /registration/
- name: csi-s3
securityContext:
privileged: true
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: cr.yandex/crp9ftr22d26age3hulg/csi-s3:0.41.1
imagePullPolicy: IfNotPresent
args:
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(NODE_ID)"
- "--v=4"
env:
- name: CSI_ENDPOINT
value: unix:///csi/csi.sock
- name: NODE_ID
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: plugin-dir
mountPath: /csi
- name: stage-dir
mountPath: /var/lib/kubelet/plugins/kubernetes.io/csi
mountPropagation: "Bidirectional"
- name: pods-mount-dir
mountPath: /var/lib/kubelet/pods
mountPropagation: "Bidirectional"
- name: fuse-device
mountPath: /dev/fuse
- name: systemd-control
mountPath: /run/systemd
volumes:
- name: registration-dir
hostPath:
path: /var/lib/kubelet/plugins_registry/
type: DirectoryOrCreate
- name: plugin-dir
hostPath:
path: /var/lib/kubelet/plugins/ru.yandex.s3.csi
type: DirectoryOrCreate
- name: stage-dir
hostPath:
path: /var/lib/kubelet/plugins/kubernetes.io/csi
type: DirectoryOrCreate
- name: pods-mount-dir
hostPath:
path: /var/lib/kubelet/pods
type: Directory
- name: fuse-device
hostPath:
path: /dev/fuse
- name: systemd-control
hostPath:
path: /run/systemd
type: DirectoryOrCreate
27 changes: 27 additions & 0 deletions kubernetes-csi/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-with-csi
labels:
app: nginx-with-csi
spec:
replicas: 1
selector:
matchLabels:
app: nginx-with-csi
template:
metadata:
labels:
app: nginx-with-csi
spec:
containers:
- name: nginx-with-csi
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html/
name: csi
volumes:
- name: csi
persistentVolumeClaim:
claimName: kube-csi-s3-pvc
readOnly: false
7 changes: 7 additions & 0 deletions kubernetes-csi/driver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
name: ru.yandex.s3.csi
spec:
attachRequired: false
podInfoOnMount: true
109 changes: 109 additions & 0 deletions kubernetes-csi/provisioner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: csi-s3-provisioner-sa
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-s3-external-provisioner-runner
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-s3-provisioner-role
subjects:
- kind: ServiceAccount
name: csi-s3-provisioner-sa
namespace: kube-system
roleRef:
kind: ClusterRole
name: csi-s3-external-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
kind: Service
apiVersion: v1
metadata:
name: csi-s3-provisioner
namespace: kube-system
labels:
app: csi-s3-provisioner
spec:
selector:
app: csi-s3-provisioner
ports:
- name: csi-s3-dummy
port: 65535
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-s3-provisioner
namespace: kube-system
spec:
serviceName: "csi-provisioner-s3"
replicas: 1
selector:
matchLabels:
app: csi-s3-provisioner
template:
metadata:
labels:
app: csi-s3-provisioner
spec:
serviceAccount: csi-s3-provisioner-sa
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
containers:
- name: csi-provisioner
image: quay.io/k8scsi/csi-provisioner:v2.1.0
args:
- "--csi-address=$(ADDRESS)"
- "--v=4"
env:
- name: ADDRESS
value: /var/lib/kubelet/plugins/ru.yandex.s3.csi/csi.sock
imagePullPolicy: "IfNotPresent"
volumeMounts:
- name: socket-dir
mountPath: /var/lib/kubelet/plugins/ru.yandex.s3.csi
- name: csi-s3
image: cr.yandex/crp9ftr22d26age3hulg/csi-s3:0.41.1
imagePullPolicy: IfNotPresent
args:
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(NODE_ID)"
- "--v=4"
env:
- name: CSI_ENDPOINT
value: unix:///var/lib/kubelet/plugins/ru.yandex.s3.csi/csi.sock
- name: NODE_ID
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: socket-dir
mountPath: /var/lib/kubelet/plugins/ru.yandex.s3.csi
volumes:
- name: socket-dir
emptyDir: {}
12 changes: 12 additions & 0 deletions kubernetes-csi/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: kube-csi-s3-pvc
namespace: default
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storageClassName: kube-csi-s3
12 changes: 12 additions & 0 deletions kubernetes-csi/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1) создаю секрет с ключами для доступа к ObjectStorage
kubectl apply -f .\secret.yaml
2) создаю starageClass, описывающий класс хранилища:
kubectl apply -f .\storage-class.yaml
3) установка драйвера:
kubectl apply -f provisioner.yaml
kubectl apply -f driver.yaml
kubectl apply -f csi-s3.yaml
4) создание pvc:
kubectl apply -f pvc.yaml
5) создать под, который будет использовать objectstorage:
kubectl apply -f .\deployment.yaml
9 changes: 9 additions & 0 deletions kubernetes-csi/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
namespace: kube-system
name: kube-csi-s3-secret
stringData:
accessKeyID: key-id
secretAccessKey: secret
endpoint: https://storage.yandexcloud.net/
17 changes: 17 additions & 0 deletions kubernetes-csi/storage-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: kube-csi-s3
provisioner: ru.yandex.s3.csi
parameters:
mounter: geesefs
options: "--memory-limit=1000 --dir-mode=0777 --file-mode=0666"
bucket: kubernetes-csi
csi.storage.k8s.io/provisioner-secret-name: kube-csi-s3-secret
csi.storage.k8s.io/provisioner-secret-namespace: kube-system
csi.storage.k8s.io/controller-publish-secret-name: kube-csi-s3-secret
csi.storage.k8s.io/controller-publish-secret-namespace: kube-system
csi.storage.k8s.io/node-stage-secret-name: kube-csi-s3-secret
csi.storage.k8s.io/node-stage-secret-namespace: kube-system
csi.storage.k8s.io/node-publish-secret-name: kube-csi-s3-secret
csi.storage.k8s.io/node-publish-secret-namespace: kube-system
Binary file added kubernetes-csi/storage.bmp
Binary file not shown.
Binary file added kubernetes-csi/volume.bmp
Binary file not shown.

0 comments on commit d33a244

Please sign in to comment.