Tạo StorageClass RWX với CMC Object Storage cho cụm K8s

Cập nhật lần cuối: 2025/01/20 11:29:56

Hướng dẫn này sẽ giúp khách hàng có thể sử dụng CMC Simple Storage Service làm nơi lưu trữ dữ liệu cho các pod CMC Kubernetes Engine.

ĐIỀU KIỆN

  • Đăng nhập tài khoản vào CMC Cloud Portal
  • Đã chuẩn bị đầy đủ các thông tin để kết nối tới dịch vụ CMC Object Storage bao gồm : Access Key, SecretKeyEndpoint
  • Đã khởi tạo thành công Cluster K8S

CÁC BƯỚC THỰC HIỆN

Khách hàng có thể thực hiện các bước sau:  

  • Truy cập Portal và lấy các thông tin của Object Storage như accessKey, secretKey và endpoint
  • Cài đặt CSI-S3 cho cụm K8s 

Bước 1 : Lấy thông tin truy cập Object Storage

  • Truy cập vào CMC Cloud Portalv2 
  • Trên thanh công cụ , chọn dịch vụ Simple Storage Service
  • Chọn S3 User
  • Tại Username của mình , chọn Show S3 key , hệ thống sẽ hiển thị ra các thông tin cần thiết để truy cập như accessKey, secretKey và endpoint

Bước 2 : Cài đặt Container Storage Interface (CSI) cho cụm K8s

Cách 1 : Triển khai với Helm

  • Thêm Repo csi-s3 cho Helm
helm repo add yandex-s3 https://yandex-cloud.github.io/k8s-csi-s3/charts
  • Tải file value.yaml về để sử dụng cho Helm
wget https://raw.githubusercontent.com/yandex-cloud/k8s-csi-s3/v0.38.3/deploy/helm/csi-s3/values.yaml
  • Chỉnh lại các thông số tương ứng với S3 Information trên portal để cài đặt csi-S3
    • accessKey: <S3 Key>
    • secretKey: <S3 Secret Key>
    • endpoint: <Endpoint>
vi values.yaml

storageClass:

  ...

  # GeeseFS mount options

  mountOptions: "--memory-limit 1000 --dir-mode 0777 --file-mode 0666"

  ...

secret:

  # Specifies whether the secret should be created

  create: true

  # Name of the secret

  name: csi-s3-secret

  # S3 Access Key

  accessKey: "<S3_Key>"

  # S3 Secret Key

  secretKey: "<S3_Secret_Key>"

  # Endpoint

  endpoint: https://<Endpoint>

  • Cài đặt csi-s3 cho cụm k8s
helm install -f values.yaml --namespace kube-system csi-s3 yandex-s3/csi-s3

 


Cách 2 : Triển khai bằng Kubectl

  • Tạo file secret.yaml với các thông số đã lấy ở Bước 1
    • accessKeyID: <S3 Key>
    • secretAccessKey: <S3 Secret Key>
    • endpoint: <Endpoint>
vi secret.yaml

apiVersion: v1

kind: Secret

metadata:

  name: csi-s3-secret

  # Namespace depends on the configuration in the storageclass.yaml

  namespace: kube-system

stringData:

  accessKeyID: <S3_Key>

  secretAccessKey: <S3_Secret_Key>

  # For AWS set it to "https://s3.<region>.amazonaws.com", for example https://s3.eu-central-1.amazonaws.com

  endpoint: https://<Endpoint>

kubectl apply -f secret.yaml
  • Triển khai driver csi-s3

kubectl create -f https://raw.githubusercontent.com/yandex-cloud/k8s-csi-s3/v0.38.3/deploy/kubernetes/provisioner.yaml

kubectl create -f https://raw.githubusercontent.com/yandex-cloud/k8s-csi-s3/v0.38.3/deploy/kubernetes/driver.yaml

kubectl create -f https://raw.githubusercontent.com/yandex-cloud/k8s-csi-s3/v0.38.3/deploy/kubernetes/csi-s3.yaml

  • Khởi tạo storage class cho csi-s3

---

kind: StorageClass

apiVersion: storage.k8s.io/v1

metadata:

  name: csi-s3

provisioner: ru.yandex.s3.csi

parameters:

  mounter: geesefs

  # you can set mount options here, for example limit memory cache size (recommended)

  options: "--memory-limit 1000 --dir-mode 0777 --file-mode 0666"

  # to use an existing bucket, specify it here:

  #bucket: some-existing-bucket

  csi.storage.k8s.io/provisioner-secret-name: csi-s3-secret

  csi.storage.k8s.io/provisioner-secret-namespace: kube-system

  csi.storage.k8s.io/controller-publish-secret-name: csi-s3-secret

  csi.storage.k8s.io/controller-publish-secret-namespace: kube-system

  csi.storage.k8s.io/node-stage-secret-name: csi-s3-secret

  csi.storage.k8s.io/node-stage-secret-namespace: kube-system

  csi.storage.k8s.io/node-publish-secret-name: csi-s3-secret

  csi.storage.k8s.io/node-publish-secret-namespace: kube-system


Bước 3 : Kiểm tra trong Cluster :

  • Truy cập Cluster K8s , kiểm tra Storageclass đã tạo 
  • Tạo 1 Pod gán với S3 Bucket
vi example.yaml
apiVersion: v1
kind: Pod
metadata:
 name: test-nginx
spec:
 containers:
   - name: test
     image: nginx
     volumeMounts:
       - name: config
         mountPath: /usr/share/nginx/html
 volumes:
   - name: config
     persistentVolumeClaim:
       claimName: pvc-nginx
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: pvc-nginx
spec:
 accessModes:
   - ReadWriteMany
 storageClassName: CSI-S3
 resources:
   requests:
     storage: 26Gi
kubectl apply -f example.yaml
  • Kiểm tra pod và persistentvolume đã tạo 
  • Kiểm tra bucket được tạo trên S3 :
    back to top

    logo

    © 2023, CMC Cloud. All rights reserved.

    Business Registration Certificate

    Giấy ĐKKD: 0102900049. Nơi cấp: Sở Kế hoạch & Đầu tư Thành phố Hà Nội

    Chịu trách nhiệm nội dung: Đặng Tùng Sơn