iT邦幫忙

2021 iThome 鐵人賽

DAY 29
0
DevOps

從煉獄走到天堂的AWS DevOps 工具及應用開發大進擊系列 第 29

D槽空間還夠嗎?擴充一下可以下載更多東西

  • 分享至 

  • twitterImage
  •  

擴充掛載

昨日有講解PV & PVC Static Provisioning的做法,今日會介紹使用StorageClass & PVC並使用AWS上的EBS來mount到Node

先來看StorageClass & PVC的關係圖,再來做詳細的介紹:
https://ithelp.ithome.com.tw/upload/images/20211013/20140172PjHRcRuiH8.png

從圖中可以看到PV是從StorageClass去自動創建出來的元件,會去建立一個符合PVC規範並且可以Bounding,這種作法稱之為Dynamic Provisioning。若對檔案的讀寫有很高的需求(IOPS),可以使用StorageClass的方法,建立EBS volume並mount作為儲存空間。

以下會進行StorageClass & PVC的實作,依照下列步驟進行前置作業:

  1. 下載IAM Policy
curl -o example-iam-
policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-ebs- csi-driver/v0.9.0/docs/example-iam-policy.json
  1. 建立IAM Policy
aws iam create-policy --policy-name AmazonEKS_EBS_CSI_Driver_Policy –
policy-document file://example-iam-policy.json
  1. AmazonEKS_EBS_CSI_Driver_Policy加到EC2 Role
    https://ithelp.ithome.com.tw/upload/images/20211013/201401726e2Ow18HNN.png
    https://ithelp.ithome.com.tw/upload/images/20211013/20140172aUM2cp2z7U.png

  2. Deploy EBS CSI Driver

kubectl apply -k "github.com/kubernetes-sigs/aws-ebs-csi-
driver/deploy/kubernetes/overlays/stable/?ref=master"

以上就是要使用EBS的前置處理,接下來會介紹StorageClass & PVC的YAML

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gp3
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
reclaimPolicy: Retain
mountOptions:
  - debug

storageclass.kubernetes.io/is-default-class: "true":設置為Default
provisioner:使用gp3需要填入ebs.csi.aws.com,若是其他的Volume要填入對應的參數
parameters:
 Type:Volume有io1, io2, gp2, gp3, sc1, st1,standard這些參數可以選擇
mountOptions:驗證mount的時候有無成功
這邊的reclaimPolicy為Retain,當Cluster或YAML被刪除,EBS依舊會保留下來;反觀,Delete就會直接刪除

pvc的設定,可以直接拿昨日的檔案,並修改storageClassName為gp3,參考如下:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypvc
spec:
  resources:
    requests:
      storage: 2Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: gp3

deploy YAML也可以拿昨日的檔案來使用,所以[Day28]不熟悉的話,會影響到今日的文章,若不熟悉的話,要看個1000次

結果

https://ithelp.ithome.com.tw/upload/images/20211013/20140172pBwMS4xyJc.png
藍勾:預設的EBS Volume
黑勾:Lens metrics Feature所產生的EBS Volume
紅勾:此篇建立的EBS Volume
綠勾:EC2再刪除時,是否會保留,此篇建立的EBS會被保留
https://ithelp.ithome.com.tw/upload/images/20211013/20140172RagC3CfXXT.png
成功將EBS Volume(gp3) mount到/var/www/html

刪除Node(EC2),驗證reclaimPolicy: Retain
https://ithelp.ithome.com.tw/upload/images/20211013/20140172O9wcB7Z7vV.png
https://ithelp.ithome.com.tw/upload/images/20211013/20140172Eo6HCuLCkD.png

此篇建立的EBS確實有保留下來,且處於available的狀態,若資料很重要的話,避免誤刪Node可以使用Retain策略,相對的,資料並不是很重要,那就可以選用Delete的方式,當Node被刪除就可以連同EBS一起刪除

今日的講解說明就到這邊,明日會做懶人包文章大解析


上一篇
只有留存下來的人事物才是你所擁有
下一篇
快速瀏覽文章的重點大進擊
系列文
從煉獄走到天堂的AWS DevOps 工具及應用開發大進擊30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言