|
| 1 | +--- |
| 2 | +title: Deploying a demo application on Scaleway Kubernetes Kapsule |
| 3 | +description: This page shows you how to deploy a demo application on Scaleway Kubernetes Kapsule |
| 4 | +tags: Kubernetes Kapsule k8S |
| 5 | +products: |
| 6 | + - kubernetes |
| 7 | +dates: |
| 8 | + validation: 2025-08-13 |
| 9 | + posted: 2025-08-13 |
| 10 | + validation_frequency: 12 |
| 11 | +--- |
| 12 | +import Requirements from '@macros/iam/requirements.mdx' |
| 13 | + |
| 14 | + |
| 15 | +# Deploy an intermediate workload on Scaleway Kubernetes Kapsule |
| 16 | + |
| 17 | +This tutorial guides you through deploying a demo application (`whoami`) on Scaleway Kubernetes Kapsule. You will create a managed Kubernetes cluster, deploy a sample application, configure an ingress controller for external access, set up auto-scaling, and test the setup. |
| 18 | +This tutorial is designed for users with a basic understanding of Kubernetes concepts like pods, deployments, services, and ingress. |
| 19 | + |
| 20 | +<Requirements /> |
| 21 | + |
| 22 | +- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization |
| 23 | +- A [Scaleway API key](/iam/how-to/create-api-keys/) for details. |
| 24 | +- Installed the tools `kubectl`, `scw`, and `helm` on your local computer |
| 25 | +- Basic familiarity with Kubernetes concepts (Pods, Deployments, Services, Ingress). |
| 26 | + |
| 27 | +## Configure Scaleway CLI |
| 28 | + |
| 29 | +Configure the [Scaleway CLI (v2)](https://github.com/scaleway/scaleway-cli) to manage your Kubernetes Kapsule cluster. |
| 30 | + |
| 31 | +1. Install the Scaleway CLI (if not already installed): |
| 32 | + |
| 33 | + ```bash |
| 34 | + curl -s https://raw.githubusercontent.com/scaleway/scaleway-cli/master/scripts/get.sh | sh |
| 35 | + ``` |
| 36 | + |
| 37 | +2. Initialize the CLI with your API key: |
| 38 | + |
| 39 | + ```bash |
| 40 | + scw init |
| 41 | + ``` |
| 42 | + |
| 43 | + Follow the prompts to enter your `SCW_ACCESS_KEY`, `SCW_SECRET_KEY`, and default region (e.g., `pl-waw` for Warsaw, Poland). |
| 44 | + |
| 45 | +## Create a Kubernetes Kapsule cluster |
| 46 | + |
| 47 | +Create a managed Kubernetes cluster using the Scaleway CLI. |
| 48 | + |
| 49 | +1. Run the following command to create a cluster with a single node pool: |
| 50 | + |
| 51 | + ```bash |
| 52 | + scw k8s cluster create name=demo-cluster version=1.32.7 pools.0.size=2 pools.0.node-type=DEV1-M pools.0.name=default pools.0.min-size=1 pools.0.max-size=3 pools.0.autoscaling=true region=pl-waw |
| 53 | + ``` |
| 54 | + |
| 55 | + - `version=1.32.7`: Specifies a [recent Kubernetes version](/kubernetes/reference-content/version-support-policy/#scaleway-kubernetes-products). |
| 56 | + - `pools.0.size=2`: Starts with two nodes. |
| 57 | + - `pools.0.min-size=1`, `pools.0.max-size=3`, `pools.0.autoscaling=true`: Enables node auto-scaling. |
| 58 | + - `region=pl-waw`: Deploys in the Warsaw region. |
| 59 | + |
| 60 | +2. Retrieve the cluster ID and download the kubeconfig file: |
| 61 | + |
| 62 | + ```bash |
| 63 | + CLUSTER_ID=$(scw k8s cluster list | grep demo-cluster | awk '{print $1}') |
| 64 | + scw k8s kubeconfig get $CLUSTER_ID > ~/.kube/demo-cluster-config |
| 65 | + export KUBECONFIG=~/.kube/demo-cluster-config |
| 66 | + ``` |
| 67 | + |
| 68 | + <Message type="tip"> |
| 69 | + Alternatively, you can copy the cluster ID from the output after cluster creation and install the kubeconfig file using the following command: |
| 70 | + ```bash |
| 71 | + scw k8s kubeconfig install <CLUSTER_ID> |
| 72 | + ``` |
| 73 | + </Message> |
| 74 | + |
| 75 | +3. Verify cluster connectivity: |
| 76 | + |
| 77 | + ```bash |
| 78 | + kubectl get nodes |
| 79 | + ``` |
| 80 | + |
| 81 | + Ensure all nodes are in the `Ready` state. |
| 82 | + |
| 83 | +## Deploy a sample application |
| 84 | + |
| 85 | +Deploy the [whoami](https://github.com/traefik/whoami) application (a well-known demo application to test cluster deployments) using a Kubernetes Deployment and Service. |
| 86 | + |
| 87 | +1. Create a file named `whoami-deployment.yaml` with the following content: |
| 88 | + |
| 89 | + ```yaml |
| 90 | + apiVersion: apps/v1 |
| 91 | + kind: Deployment |
| 92 | + metadata: |
| 93 | + name: whoami |
| 94 | + namespace: default |
| 95 | + spec: |
| 96 | + replicas: 2 |
| 97 | + selector: |
| 98 | + matchLabels: |
| 99 | + app: whoami |
| 100 | + template: |
| 101 | + metadata: |
| 102 | + labels: |
| 103 | + app: whoami |
| 104 | + spec: |
| 105 | + containers: |
| 106 | + - name: whoami |
| 107 | + image: traefik/whoami:latest |
| 108 | + ports: |
| 109 | + - containerPort: 80 |
| 110 | + resources: |
| 111 | + requests: |
| 112 | + cpu: "100m" |
| 113 | + memory: "128Mi" |
| 114 | + limits: |
| 115 | + cpu: "200m" |
| 116 | + memory: "256Mi" |
| 117 | + --- |
| 118 | + apiVersion: v1 |
| 119 | + kind: Service |
| 120 | + metadata: |
| 121 | + name: whoami-service |
| 122 | + namespace: default |
| 123 | + spec: |
| 124 | + selector: |
| 125 | + app: whoami |
| 126 | + ports: |
| 127 | + - protocol: TCP |
| 128 | + port: 80 |
| 129 | + targetPort: 80 |
| 130 | + type: ClusterIP |
| 131 | + ``` |
| 132 | +
|
| 133 | +2. Apply the configuration: |
| 134 | +
|
| 135 | + ```bash |
| 136 | + kubectl apply -f whoami-deployment.yaml |
| 137 | + ``` |
| 138 | + |
| 139 | +3. Verify the deployment and service: |
| 140 | + |
| 141 | + ```bash |
| 142 | + kubectl get deployments |
| 143 | + kubectl get pods |
| 144 | + kubectl get services |
| 145 | + ``` |
| 146 | + |
| 147 | +## Configure an ingress controller |
| 148 | + |
| 149 | +Expose the `whoami` application externally using an [Nginx ingress controller](/kubernetes/reference-content/lb-ingress-controller/). |
| 150 | + |
| 151 | +<Message type="note"> |
| 152 | + Before proceeding, ensure the [Helm package manager](/tutorials/kubernetes-package-management-helm/) is installed on your local machine. If it is not already installed, you will need to set it up first. |
| 153 | +</Message> |
| 154 | + |
| 155 | +1. Install the Nginx ingress controller using Helm: |
| 156 | + |
| 157 | + ```bash |
| 158 | + helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx |
| 159 | + helm repo update |
| 160 | + helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace |
| 161 | + ``` |
| 162 | + |
| 163 | +2. Create a file named `whoami-ingress.yaml` with the following content: |
| 164 | + |
| 165 | + ```yaml |
| 166 | + apiVersion: networking.k8s.io/v1 |
| 167 | + kind: Ingress |
| 168 | + metadata: |
| 169 | + name: whoami-ingress |
| 170 | + namespace: default |
| 171 | + annotations: |
| 172 | + nginx.ingress.kubernetes.io/rewrite-target: / |
| 173 | + spec: |
| 174 | + ingressClassName: nginx |
| 175 | + rules: |
| 176 | + - host: whoami.example.com |
| 177 | + http: |
| 178 | + paths: |
| 179 | + - path: / |
| 180 | + pathType: Prefix |
| 181 | + backend: |
| 182 | + service: |
| 183 | + name: whoami-service |
| 184 | + port: |
| 185 | + number: 80 |
| 186 | + ``` |
| 187 | +
|
| 188 | +3. Apply the Ingress configuration: |
| 189 | +
|
| 190 | + ```bash |
| 191 | + kubectl apply -f whoami-ingress.yaml |
| 192 | + ``` |
| 193 | + |
| 194 | +4. Retrieve the external IP of the Ingress controller: |
| 195 | + |
| 196 | + ```bash |
| 197 | + kubectl get svc -n ingress-nginx ingress-nginx-controller |
| 198 | + ``` |
| 199 | + |
| 200 | +## Set up auto-scaling |
| 201 | + |
| 202 | +Configure [Horizontal Pod Autoscaling (HPA)](https://www.scaleway.com/en/blog/understanding-kubernetes-autoscaling/) to dynamically scale the `whoami` application based on CPU usage. |
| 203 | + |
| 204 | +1. Create a file named `whoami-hpa.yaml` with the following content: |
| 205 | + |
| 206 | + ```yaml |
| 207 | + apiVersion: autoscaling/v2 |
| 208 | + kind: HorizontalPodAutoscaler |
| 209 | + metadata: |
| 210 | + name: whoami-hpa |
| 211 | + namespace: default |
| 212 | + spec: |
| 213 | + scaleTargetRef: |
| 214 | + apiVersion: apps/v1 |
| 215 | + kind: Deployment |
| 216 | + name: whoami |
| 217 | + minReplicas: 2 |
| 218 | + maxReplicas: 5 |
| 219 | + metrics: |
| 220 | + - type: Resource |
| 221 | + resource: |
| 222 | + name: cpu |
| 223 | + target: |
| 224 | + type: Utilization |
| 225 | + averageUtilization: 70 |
| 226 | + ``` |
| 227 | +
|
| 228 | +2. Apply the HPA configuration: |
| 229 | +
|
| 230 | + ```bash |
| 231 | + kubectl apply -f whoami-hpa.yaml |
| 232 | + ``` |
| 233 | + |
| 234 | +3. Verify the HPA status: |
| 235 | + |
| 236 | + ```bash |
| 237 | + kubectl get hpa |
| 238 | + kubectl describe hpa whoami-hpa |
| 239 | + ``` |
| 240 | + |
| 241 | +## Test the application |
| 242 | + |
| 243 | +1. Get the Ingress controller’s external IP: |
| 244 | + |
| 245 | + ```bash |
| 246 | + INGRESS_IP=$(kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}') |
| 247 | + ``` |
| 248 | + |
| 249 | +2. Test the application by sending an HTTP request (replace `whoami.example.com` with your domain or use the IP directly): |
| 250 | + |
| 251 | + ```bash |
| 252 | + curl -H "Host: whoami.example.com" http://$INGRESS_IP |
| 253 | + ``` |
| 254 | + |
| 255 | +3. Simulate load to trigger auto-scaling (optional): |
| 256 | + |
| 257 | + ```bash |
| 258 | + kubectl run -i --tty load-generator --image=busybox --restart=Never -- /bin/sh -c "while true; do wget -q -O- http://whoami-service.default.svc.cluster.local; done" |
| 259 | + ``` |
| 260 | + |
| 261 | +4. Open another terminal and monitor pod scaling: |
| 262 | + |
| 263 | + ```bash |
| 264 | + kubectl get pods -w |
| 265 | + kubectl get hpa -w |
| 266 | + ``` |
| 267 | + |
| 268 | +## Clean up |
| 269 | + |
| 270 | +Delete the cluster to avoid unnecessary costs. |
| 271 | + |
| 272 | +1. Delete the cluster: |
| 273 | + |
| 274 | + ```bash |
| 275 | + scw k8s cluster delete $CLUSTER_ID |
| 276 | + ``` |
| 277 | + |
| 278 | +2. Confirm the cluster is deleted: |
| 279 | + |
| 280 | + ```bash |
| 281 | + scw k8s cluster list |
| 282 | + ``` |
| 283 | + |
| 284 | +## Conclusion |
| 285 | + |
| 286 | +This tutorial has guided you through the full lifecycle of a Kubernetes deployment, from creating a cluster and deploying an application to configuring ingress, enabling autoscaling, performing load testing, monitoring performance, and cleaning up resources. |
| 287 | +You have completed the first steps to effectively manage cloud-native applications on Scaleway, with a focus on both manual resource control and automated scaling to build resilient, efficient, and scalable systems. |
0 commit comments