Skip to content

Commit f4b4ef2

Browse files
fmederyFrederic Medery
and
Frederic Medery
authored
Update statefulset lab (#1063)
* add package json file * Update statefulSet lab * EBS-CSI-DRIVER is now installed using HELM * using IRSA for the driver * update the number of mysql pods due to t3 machines instead of m5 * update pictures * Cosmetic changes based on linter * Except for statefulset, move from downloading YAML file to create them inline * delete all unused files Co-authored-by: Frederic Medery <[email protected]>
1 parent 03d8e9e commit f4b4ef2

20 files changed

+284
-337
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ terraform.tfstate
77
terraform.tfstate.backup
88
.DS_Store
99
*.swp
10+
.vscode

content/beginner/170_statefulset/_index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ tags:
1010
# Stateful containers using StatefulSets
1111

1212
[StatefulSet](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods, suitable for applications that require one or more of the following.
13+
1314
* Stable, unique network identifiers
1415
* Stable, persistent storage
1516
* Ordered, graceful deployment and scaling
1617
* Ordered, automated rolling updates
1718

18-
In this Chapter, we will review how to deploy MySQL database using `StatefulSet` and `Amazon Elastic Block Store` (EBS) as [PersistentVolume](https://kubernetes.io/docs/concepts/storage/persistent-volumes/). The example is a MySQL single leader topology with multiple followers running asynchronous replication.
19+
In this Chapter, we will review how to deploy MySQL database using `StatefulSet` and `Amazon Elastic Block Store` (EBS) as [PersistentVolume](https://kubernetes.io/docs/concepts/storage/persistent-volumes/). The example is a MySQL single leader topology with a follower running asynchronous replication.

content/beginner/170_statefulset/cleanup.md

+23-9
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,35 @@ date: 2018-08-07T08:30:11-07:00
44
weight: 40
55
---
66
```sh
7+
export EBS_CSI_POLICY_NAME="Amazon_EBS_CSI_Driver"
8+
export EBS_CSI_POLICY_ARN=$(aws --region ${AWS_REGION} iam list-policies --query 'Policies[?PolicyName==`'${EBS_CSI_POLICY_NAME}'`].Arn' --output text)
9+
10+
kubectl delete \
11+
-f ${HOME}/environment/ebs_statefulset/mysql-statefulset.yaml \
12+
-f ${HOME}/environment/ebs_statefulset/mysql-services.yaml \
13+
-f ${HOME}/environment/ebs_statefulset/mysql-configmap.yaml \
14+
-f ${HOME}/environment/ebs_statefulset/mysql-storageclass.yaml
15+
716
# Delete the mysql namespace
817
kubectl delete namespace mysql
918

10-
# Detach the IAM Amazon_EBS_CSI_Driver policy from your worker node instance profile.
11-
export EBS_CNI_POLICY_NAME="Amazon_EBS_CSI_Driver"
12-
export EBS_CNI_POLICY_ARN=$(aws --region ${AWS_REGION} iam list-policies --query 'Policies[?PolicyName==`'${EBS_CNI_POLICY_NAME}'`].Arn' --output text)
19+
# Uninstall the aws-ebs-csi-driver
20+
helm -n kube-system uninstall aws-ebs-csi-driver
1321

14-
aws iam detach-role-policy \
15-
--region ${AWS_REGION} \
16-
--policy-arn ${EBS_CNI_POLICY_ARN} \
17-
--role-name ${ROLE_NAME}
22+
# Delete the service account
23+
eksctl delete iamserviceaccount \
24+
--cluster eksworkshop-eksctl \
25+
--namespace kube-system \
26+
--name ebs-csi-controller-irsa \
27+
--wait
1828

1929
# Delete the IAM Amazon_EBS_CSI_Driver policy
2030
aws iam delete-policy \
2131
--region ${AWS_REGION} \
22-
--policy-arn ${EBS_CNI_POLICY_ARN}
32+
--policy-arn ${EBS_CSI_POLICY_ARN}
33+
34+
cd ${HOME}/environment
35+
rm -rf ${HOME}/environment/ebs_statefulset
2336
```
24-
## Congratulation! You've finished the StatefulSets lab.
37+
38+
## Congratulation! You've finished the StatefulSets lab

content/beginner/170_statefulset/configmap.files/mysql-configmap.yml

-16
This file was deleted.

content/beginner/170_statefulset/configmap.md

+20-21
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,26 @@ date: 2018-08-07T08:30:11-07:00
44
weight: 10
55
---
66

7-
#### Introduction
8-
[ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) allow you to decouple configuration artifacts and secrets from image content to keep containerized applications portable. Using ConfigMap, you can independently control MySQL configuration.
7+
## Introduction
8+
9+
[ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) allow you to decouple configuration artifacts and secrets from image content to keep containerized applications portable. Using ConfigMap, you can independently control MySQL configuration.
10+
11+
## Create the mysql Namespace
912

10-
#### Create the mysql Namespace
1113
We will create a new `Namespace` called `mysql` that will host all the components.
14+
1215
```sh
1316
kubectl create namespace mysql
1417
```
1518

16-
#### Create ConfigMap
17-
Run the following commands to download the `ConfigMap`.
18-
```sh
19-
cd ~/environment/templates
20-
wget https://eksworkshop.com/beginner/170_statefulset/configmap.files/mysql-configmap.yml
19+
## Create ConfigMap
2120

22-
```
21+
Run the following commands to download the `ConfigMap`.
2322

24-
Check the configuration of mysql-configmap.yml file.
2523
```sh
26-
cat ~/environment/templates/mysql-configmap.yml
27-
```
24+
cd ${HOME}/environment/ebs_statefulset
2825

29-
The `ConfigMap` stores master.cnf, slave.cnf and passes them when initializing leader and follower pods defined in StatefulSet:
30-
* **master.cnf** is for the MySQL leader pod which has binary log option (log-bin) to provides a record of the data changes to be sent to follower servers.
31-
* **slave.cnf** is for follower pods which have super-read-only option.
32-
{{< output >}}
26+
cat << EoF > ${HOME}/environment/ebs_statefulset/mysql-configmap.yaml
3327
apiVersion: v1
3428
kind: ConfigMap
3529
metadata:
@@ -43,14 +37,19 @@ data:
4337
[mysqld]
4438
log-bin
4539
slave.cnf: |
46-
# Apply this config only on follower.
40+
# Apply this config only on followers.
4741
[mysqld]
4842
super-read-only
49-
{{< /output >}}
43+
EoF
44+
```
45+
46+
The `ConfigMap` stores `master.cnf`, `slave.cnf` and passes them when initializing leader and follower pods defined in StatefulSet:
47+
48+
* **master.cnf** is for the MySQL leader pod which has binary log option (log-bin) to provides a record of the data changes to be sent to follower servers.
49+
* **slave.cnf** is for follower pods which have super-read-only option.
5050

5151
Create "mysql-config" `ConfigMap`.
52+
5253
```sh
53-
kubectl create -f ~/environment/templates/mysql-configmap.yml
54+
kubectl create -f ${HOME}/environment/ebs_statefulset/mysql-configmap.yaml
5455
```
55-
56-
{{%attachments title="Related files" pattern=".yml"/%}}

content/beginner/170_statefulset/ebs_csi_driver.files/attacher-binding.yml

-3
This file was deleted.

content/beginner/170_statefulset/ebs_csi_driver.files/deployment.yml

-3
This file was deleted.

content/beginner/170_statefulset/ebs_csi_driver.files/kustomization.yml

-28
This file was deleted.

content/beginner/170_statefulset/ebs_csi_driver.files/provisioner-binding.yml

-3
This file was deleted.

content/beginner/170_statefulset/ebs_csi_driver.md

+62-33
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,108 @@ title: "Amazon EBS CSI Driver"
44
date: 2020-02-23T13:57:00-08:00
55
weight: 4
66
---
7+
## About Container Storage Interface (CSI)
8+
9+
[The Container Storage Interface](https://github.com/container-storage-interface/spec/blob/master/spec.md) (CSI) is a standard for exposing arbitrary block and file storage systems to containerized workloads on Container Orchestration Systems (COs) like Kubernetes.
10+
11+
Using CSI third-party storage providers can write and deploy plugins exposing new storage systems in Kubernetes without ever having to touch the core Kubernetes code.
712

813
## About the Amazon EBS CSI Driver
914

10-
On Amazon EKS, the open-source [EBS Container Storage Interface (CSI)
11-
driver](https://github.com/kubernetes-sigs/aws-ebs-csi-driver) is used to manage
12-
the attachment of Amazon EBS block storage volumes to Kubernetes Pods.
15+
The [Amazon Elastic Block Store (Amazon EBS) Container Storage Interface (CSI) driver](https://github.com/kubernetes-sigs/aws-ebs-csi-driver) provides a CSI interface that allows Amazon Elastic Kubernetes Service (Amazon EKS) clusters to manage the lifecycle of Amazon EBS volumes for persistent volumes.
16+
17+
This topic shows you how to deploy the Amazon EBS CSI Driver to your Amazon EKS cluster and verify that it works.
1318

1419
## Configure IAM Policy
1520

16-
The CSI driver is deployed as set of Kubernetes Pods. These Pods must have
17-
permission to perform EBS API operations, such as creating and deleting volumes,
18-
and attaching volumes to the EC2 worker nodes that comprise the cluster.
21+
The CSI driver is deployed as set of Kubernetes Pods. These Pods must have permission to perform EBS API operations, such as creating and deleting volumes, and attaching volumes to the EC2 worker nodes that comprise the cluster.
1922

2023
First, let's download the policy JSON document, and create an IAM Policy from it:
2124

2225
```sh
23-
mkdir ~/environment/ebs_csi_driver
24-
cd ~/environment/ebs_csi_driver
25-
curl -sSL -o ebs-csi-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-ebs-csi-driver/v0.4.0/docs/example-iam-policy.json
26-
2726
export EBS_CSI_POLICY_NAME="Amazon_EBS_CSI_Driver"
2827

28+
mkdir ${HOME}/environment/ebs_statefulset
29+
cd ${HOME}/environment/ebs_statefulset
30+
31+
# download the IAM policy document
32+
curl -sSL -o ebs-csi-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-ebs-csi-driver/master/docs/example-iam-policy.json
33+
34+
# Create the IAM policy
2935
aws iam create-policy \
3036
--region ${AWS_REGION} \
3137
--policy-name ${EBS_CSI_POLICY_NAME} \
32-
--policy-document file://ebs-csi-policy.json
38+
--policy-document file://${HOME}/environment/ebs_statefulset/ebs-csi-policy.json
3339

40+
# export the policy ARN as a variable
3441
export EBS_CSI_POLICY_ARN=$(aws --region ${AWS_REGION} iam list-policies --query 'Policies[?PolicyName==`'$EBS_CSI_POLICY_NAME'`].Arn' --output text)
3542
```
3643

3744
## Configure IAM Role for Service Account
3845

39-
Next, we'll ask `eksctl` to create an IAM Role that contains the IAM Policy we
40-
created, and associate it with a Kubernetes Service Account called
41-
`ebs-csi-controller-irsa` that will be used by the CSI Driver:
46+
You can associate an IAM role with a Kubernetes service account. This service account can then provide AWS permissions to the containers in any pod that uses that service account. With this feature, you no longer need to provide extended permissions to the Amazon EKS node IAM role so that pods on that node can call AWS APIs.
47+
48+
We'll ask `eksctl` to create an IAM Role that contains the IAM Policy we just created, and associate it with a Kubernetes Service Account called `ebs-csi-controller-irsa` that will be used by the CSI Driver:
4249

4350
```sh
44-
eksctl utils associate-iam-oidc-provider --region=$AWS_REGION --cluster=eksworkshop-eksctl --approve
51+
# Create an IAM OIDC provider for your cluster
52+
eksctl utils associate-iam-oidc-provider \
53+
--region=$AWS_REGION \
54+
--cluster=eksworkshop-eksctl \
55+
--approve
4556

46-
eksctl create iamserviceaccount --cluster eksworkshop-eksctl \
57+
# Create a service account
58+
eksctl create iamserviceaccount \
59+
--cluster eksworkshop-eksctl \
4760
--name ebs-csi-controller-irsa \
4861
--namespace kube-system \
4962
--attach-policy-arn $EBS_CSI_POLICY_ARN \
5063
--override-existing-serviceaccounts \
5164
--approve
5265
```
5366

54-
## Deploy EBS CSI Driver
67+
## Deploy the Amazon EBS CSI Driver
5568

56-
Finally, we can deploy the driver.
69+
Finally, we can deploy the driver using helm.
5770

58-
First, we'll need to download a few files. Run:
71+
{{% notice note %}}
72+
If Helm is not installed, [click here the instruction](/beginner/060_helm/helm_intro/install/)
73+
{{% /notice %}}
5974

6075
```sh
61-
cd ~/environment/ebs_csi_driver
62-
for file in kustomization.yml deployment.yml attacher-binding.yml provisioner-binding.yml; do
63-
curl -sSLO https://raw.githubusercontent.com/aws-samples/eks-workshop/main/content/beginner/170_statefulset/ebs_csi_driver.files/$file
64-
done
76+
# add the aws-ebs-csi-driver as a helm repo
77+
helm repo add aws-ebs-csi-driver https://kubernetes-sigs.github.io/aws-ebs-csi-driver
78+
79+
# search for the driver
80+
helm search repo aws-ebs-csi-driver
6581
```
6682

67-
To complete the deployment:
83+
output
84+
{{< output >}}
85+
NAME CHART VERSION APP VERSION DESCRIPTION
86+
aws-ebs-csi-driver/aws-ebs-csi-driver 0.9.8 0.9.0 A Helm chart for AWS EBS CSI Driver
87+
{{< /output >}}
6888

6989
```sh
70-
kubectl apply -k ~/environment/ebs_csi_driver
90+
helm upgrade --install aws-ebs-csi-driver \
91+
--version=0.9.8 \
92+
--namespace kube-system \
93+
--set serviceAccount.controller.create=false \
94+
--set serviceAccount.snapshot.create=false \
95+
--set enableVolumeScheduling=true \
96+
--set enableVolumeResizing=true \
97+
--set enableVolumeSnapshot=true \
98+
--set serviceAccount.snapshot.name=ebs-csi-controller-irsa \
99+
--set serviceAccount.controller.name=ebs-csi-controller-irsa \
100+
aws-ebs-csi-driver/aws-ebs-csi-driver
101+
102+
kubectl -n kube-system rollout status deployment ebs-csi-controller
71103
```
72104

105+
Output
106+
73107
{{< output >}}
74-
serviceaccount/ebs-csi-controller-sa created
75-
clusterrole.rbac.authorization.k8s.io/ebs-external-attacher-role created
76-
clusterrole.rbac.authorization.k8s.io/ebs-external-provisioner-role created
77-
clusterrolebinding.rbac.authorization.k8s.io/ebs-csi-attacher-binding created
78-
clusterrolebinding.rbac.authorization.k8s.io/ebs-csi-provisioner-binding created
79-
deployment.apps/ebs-csi-controller created
80-
daemonset.apps/ebs-csi-node created
81-
csidriver.storage.k8s.io/ebs.csi.aws.com created
108+
Waiting for deployment "ebs-csi-controller" rollout to finish: 0 of 2 updated replicas are available...
109+
Waiting for deployment "ebs-csi-controller" rollout to finish: 1 of 2 updated replicas are available...
110+
deployment "ebs-csi-controller" successfully rolled out
82111
{{< /output >}}

content/beginner/170_statefulset/services.files/mysql-services.yml

-31
This file was deleted.

0 commit comments

Comments
 (0)