> For the complete documentation index, see [llms.txt](https://bagus-cahyono.gitbook.io/programming-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bagus-cahyono.gitbook.io/programming-notes/cka/07_manual_scaling.md).

# Scaling: Manual

The `kubectl scale` command manually adjusts the number of pod replicas for a Deployment, ReplicaSet, StatefulSet, or Job.

This is useful when you want to:

* Increase replicas to handle more traffic.
* Reduce replicas to save resources.
* Perform manual scaling when **Horizontal Pod Autoscaler (HPA)** is not required

## Basic Syntax Usage

```bash
kubectl scale <resource-type> <resource-name> --replicas=<number>
```

* `<resource-type>`: Type of resource (e.g., `deployment`, `replicaset`, `statefulset`, `job`).
* `<resource-name>`: The name of the resource you want to scale.
* `--replicas=<number>`: Desired number of pod replicas.

## Scaling Deployment

Lets create a deployment using `nginx` image.

```bash
➜ kubectl create deployment my-nginx --image=nginx
deployment.apps/my-nginx created
```

It will create a deployment with replicas defaulted to `1`.

```bash
➜ kubectl get deployment my-nginx 
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
my-nginx   1/1     1            1           32s
```

Now lets scale the newly created deployment to `3` replicas using this command below.

```bash
➜ kubectl scale deployment my-nginx --replicas=3
deployment.apps/my-nginx scaled
```

Now if you check teh deployments again, we will have `3` replicas.

```bash
➜ kubectl get deployments my-nginx
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
my-nginx   3/3     3            3  
```

## Others

To scale `replicaset`, `statefulset`, and `job` is similar with scaling deployment, we only need to specify the resource type, resource name, and number of replicas in `kubectl apply` command.

Note that this changes are not persisted. If you have `yaml` file for your deployment definition you need to change the `spec.replicas` value.

## References

* <https://kubernetes.io/docs/reference/kubectl/generated/kubectl_scale/>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bagus-cahyono.gitbook.io/programming-notes/cka/07_manual_scaling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
