|
| 1 | +--- |
| 2 | +title: Deploy a Kubernetes cluster using magnum Capi driver with autoscaling feature |
| 3 | +order: 4 |
| 4 | +duration: 25 |
| 5 | +--- |
| 6 | + |
| 7 | +In this section, we will deploy a kubernetes cluster with autoscaling feature [Cluster Autoscaler](https://cluster-api.sigs.k8s.io/tasks/automated-machine-management/autoscaling). |
| 8 | + |
| 9 | +1. Create a Kubernetes cluster with autoscaling enabled |
| 10 | + |
| 11 | + ``` |
| 12 | + $ openstack coe cluster create --cluster-template \ |
| 13 | + kubernetes-v1.31.1-ardc-syd-1-v5 --master-count 1 --node-count 1 \ |
| 14 | + --labels auto_scaling_enabled=true,min_node_count=1,max_node_count=3 \ |
| 15 | + --keypair <project key> mycluster |
| 16 | + Request to create cluster cae2a382-26a5-438d-bbdc-e694249bbede accepted |
| 17 | +
|
| 18 | + ``` |
| 19 | + |
| 20 | +2. Verify status of autoscaling label |
| 21 | + |
| 22 | + ``` |
| 23 | + $ openstack coe cluster show mycluster -c labels_added |
| 24 | + +--------------+--------------------------------------------------------------------------------+ |
| 25 | + | Field | Value | |
| 26 | + +--------------+--------------------------------------------------------------------------------+ |
| 27 | + | labels_added | {'auto_scaling_enabled': 'true', 'min_node_count': '1', 'max_node_count': '3'} | |
| 28 | + +--------------+--------------------------------------------------------------------------------+ |
| 29 | +
|
| 30 | + ``` |
| 31 | + |
| 32 | +3. Verify whether the cluster creation is successfully created |
| 33 | + |
| 34 | + ``` |
| 35 | + $ openstack coe cluster list |
| 36 | + +--------------------------------------+-----------+---------+------------+--------------+--------------------+---------------+ |
| 37 | + | uuid | name | keypair | node_count | master_count | status | health_status | |
| 38 | + +--------------------------------------+-----------+---------+------------+--------------+--------------------+---------------+ |
| 39 | + | cae2a382-26a5-438d-bbdc-e694249bbede | mycluster | xxxxxx | 1 | 1 | UPDATE_COMPLETE | HEALTHY | |
| 40 | + +--------------------------------------+-----------+---------+------------+--------------+--------------------+---------------+ |
| 41 | +
|
| 42 | + ``` |
| 43 | + |
| 44 | +4. Download the kubeconfig file and verify the cluster nodes using kubectl in accordance with the [Administering a Cluster]({{ site.baseurl }}/kubernetes/03-administer-cluster) in Kubernetes tutorial |
| 45 | + |
| 46 | +5. Deploy an application - ngnix.yaml |
| 47 | + |
| 48 | + ``` |
| 49 | + apiVersion: apps/v1 |
| 50 | + kind: Deployment |
| 51 | + metadata: |
| 52 | + name: nginx-deployment |
| 53 | + spec: |
| 54 | + selector: |
| 55 | + matchLabels: |
| 56 | + app: nginx |
| 57 | + replicas: 3 |
| 58 | + template: |
| 59 | + metadata: |
| 60 | + labels: |
| 61 | + app: nginx |
| 62 | + spec: |
| 63 | + containers: |
| 64 | + - name: nginx |
| 65 | + image: nginx:1.14.2 |
| 66 | + ports: |
| 67 | + - containerPort: 80 |
| 68 | +
|
| 69 | + ``` |
| 70 | + |
| 71 | + ``` |
| 72 | + kubectl apply -f nginx.yaml |
| 73 | + ``` |
| 74 | + |
| 75 | +6. Deploy application and validate the deployment |
| 76 | + |
| 77 | + ``` |
| 78 | + kubectl get deployments |
| 79 | + ``` |
| 80 | + |
| 81 | + ``` |
| 82 | + NAME READY UP-TO-DATE AVAILABLE AGE |
| 83 | + nginx-deployment 3/3 3 3 8m44s |
| 84 | + $ kubectl get pods |
| 85 | + NAME READY STATUS RESTARTS AGE |
| 86 | + nginx-deployment-d556bf558-7phtc 1/1 Running 0 9m11s |
| 87 | + nginx-deployment-d556bf558-98d68 1/1 Running 0 9m11s |
| 88 | + nginx-deployment-d556bf558-shqt2 1/1 Running 0 9m11s |
| 89 | + $ kubectl get nodes |
| 90 | + NAME STATUS ROLES AGE VERSION |
| 91 | + mycluster-l76uten6iljx-control-plane-xlmq4 Ready control-plane 42m v1.31.1 |
| 92 | + mycluster-l76uten6iljx-default-worker-4dqrj-cwmjq Ready <none> 39m v1.31.1 |
| 93 | +
|
| 94 | + ``` |
| 95 | + |
| 96 | +7. Scaling up the nginx application deployment |
| 97 | + |
| 98 | + The number of NGINX web server replicas deployed must be carefully adjusted based on the configuration of the Kubernetes worker nodes. |
| 99 | + For example, in a cluster where each worker node is configured with 4 vCPUs and 8 GB of memory (m3.medium), a larger number of replicas may be |
| 100 | + required to saturate available resources and trigger the provisioning of additional nodes. |
| 101 | + |
| 102 | + ``` |
| 103 | + kubectl scale deployment --replicas=120 nginx-deployment |
| 104 | + ``` |
| 105 | + |
| 106 | + ``` |
| 107 | + deployment.apps/nginx-deployment scaled |
| 108 | +
|
| 109 | + ``` |
| 110 | + |
| 111 | + ``` |
| 112 | + kubectl get deployments |
| 113 | + ``` |
| 114 | + |
| 115 | + ``` |
| 116 | + NAME READY UP-TO-DATE AVAILABLE AGE |
| 117 | + nginx-deployment 101/120 120 101 14m |
| 118 | + $ kubectl get deployments |
| 119 | + NAME READY UP-TO-DATE AVAILABLE AGE |
| 120 | + nginx-deployment 120/120 120 120 20m |
| 121 | + $ os coe cluster list |
| 122 | + +--------------------------------------+-----------+---------+------------+--------------+-----------------+---------------+ |
| 123 | + | uuid | name | keypair | node_count | master_count | status | health_status | |
| 124 | + +--------------------------------------+-----------+---------+------------+--------------+-----------------+---------------+ |
| 125 | + | cae2a382-26a5-438d-bbdc-e694249bbede | mycluster | xxxxxx | 1 | 1 | CREATE_COMPLETE | HEALTHY | |
| 126 | + +--------------------------------------+-----------+---------+------------+--------------+-----------------+---------------+ |
| 127 | + $ kubectl get nodes |
| 128 | + NAME STATUS ROLES AGE VERSION |
| 129 | + mycluster-l76uten6iljx-control-plane-xlmq4 Ready control-plane 51m v1.31.1 |
| 130 | + mycluster-l76uten6iljx-default-worker-4dqrj-br8p9 Ready <none> 66s v1.31.1 |
| 131 | + mycluster-l76uten6iljx-default-worker-4dqrj-cwmjq Ready <none> 48m v1.31.1 |
| 132 | +
|
| 133 | + ``` |
| 134 | + |
| 135 | +8. Scaling down the nginx application deployment |
| 136 | + |
| 137 | + ``` |
| 138 | + kubectl scale deployment --replicas=2 nginx-deployment |
| 139 | + ``` |
| 140 | + |
| 141 | + ``` |
| 142 | + deployment.apps/nginx-deployment scaled |
| 143 | +
|
| 144 | + ``` |
| 145 | + |
| 146 | + ``` |
| 147 | + kubectl get deployments |
| 148 | + ``` |
| 149 | + |
| 150 | + ``` |
| 151 | + NAME READY UP-TO-DATE AVAILABLE AGE |
| 152 | + nginx-deployment 2/2 2 2 37m |
| 153 | + $ kubectl get nodes |
| 154 | + NAME STATUS ROLES AGE VERSION |
| 155 | + mycluster-l76uten6iljx-control-plane-xlmq4 Ready control-plane 100m v1.31.1 |
| 156 | + mycluster-l76uten6iljx-default-worker-4dqrj-cwmjq Ready <none> 97m v1.31.1 |
| 157 | + $ os coe cluster list |
| 158 | + +--------------------------------------+-----------+---------+------------+--------------+-----------------+---------------+ |
| 159 | + | uuid | name | keypair | node_count | master_count | status | health_status | |
| 160 | + +--------------------------------------+-----------+---------+------------+--------------+-----------------+---------------+ |
| 161 | + | cae2a382-26a5-438d-bbdc-e694249bbede | mycluster | xxxxxx | 1 | 1 | CREATE_COMPLETE | HEALTHY | |
| 162 | + +--------------------------------------+-----------+---------+------------+--------------+-----------------+---------------+ |
| 163 | +
|
| 164 | + ``` |
| 165 | + |
| 166 | +Note: Please allow several minutes for the scale-down process to complete, as the typical duration ranges between 7 and 10 minutes. |
| 167 | +## More information |
| 168 | + |
| 169 | +For more information, refer to: |
| 170 | +- [Cluster Autoscaler](https://cluster-api.sigs.k8s.io/tasks/automated-machine-management/autoscaling) |
0 commit comments