⎈ k8s knowledge compiler

Managing Workloads [page]deterministic

concepts

You've deployed your application and exposed it via a Service. Now what? Kubernetes provides a number of tools to help you manage your application deployment, including scaling and updating.

## Organizing resource configurations

Many applications require multiple resources to be created, such as a Deployment along with a Service. Management of multiple resources can be simplified by grouping them together in the same file (separated by `---` in YAML). For example:

Multiple resources can be created the same way as a single resource:

```shell kubectl apply -f https://k8s.io/examples/application/nginx-app.yaml ```

```none service/my-nginx-svc created deployment.apps/my-nginx created ```

The resources will be created in the order they appear in the manifest. Therefore, it's best to specify the Service first, since that will ensure the scheduler can spread the pods associated with the Service as they are created by the controller(s), such as Deployment.

`kubectl apply` also accepts multiple `-f` arguments:

```shell kubectl apply -f https://k8s.io/examples/application/nginx/nginx-svc.yaml \ -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml ```

It is a recommended practice to put resources related to the same microservice or application tier into the same file, and to group all of the files associated with your application in the same directory. If the tiers of your application bind to each other using DNS, you can deploy all of the components of your stack together.

A URL can also be specified as a configuration source, which is handy for deploying directly from manifests in your source control system:

```shell kubectl apply -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml ```

```none deployment.apps/my-nginx created ```

If you need to define more manifests, such as adding a ConfigMap, you can do that too.

### External tools

This section lists only the most common tools used for managing workloads on Kubernetes. To see a larger list, view [Application definition and image build](https://landscape.cncf.io/guide#app-definition-and-development--application-definition-image-build) in the [CNCF](#gloss:cncf) Landscape.

#### Helm {#external-tool-helm}

[Helm](https://helm.sh/) is a tool for managing packages of pre-configured Kubernetes resources. These packages are known as _Helm charts_.

#### Kustomize {#external-tool-kustomize}

[Kustomize](https://kustomize.io/) traverses a Kubernetes manifest to add, remove or update configuration options. It is available both as a standalone binary and as a [native feature](/docs/tasks/manage-kubernetes-objects/kustomization/) of kubectl.

## Bulk operations in kubectl

Resource creation isn't the only operation that `kubectl` can perform in bulk. It can also extract resource names from configuration files in order to perform other operations, in particular to delete the same resources you created:

```shell kubectl delete -f https://k8s.io/examples/application/nginx-app.yaml ```

```none deployment.apps "my-nginx" deleted service "my-nginx-svc" deleted ```

In the case of two resources, you can specify both resources on the command line using the resource/name syntax:

```shell kubectl delete deployments/my-nginx services/my-nginx-svc ```

For larger numbers of resources, you'll find it easier to specify the selector (label query) specified using `-l` or `--selector`, to filter resources by their labels:

```shell kubectl delete deployment,services -l app=nginx ```

```none deployment.apps "my-nginx" deleted service "my-nginx-svc" deleted ```

### Chaining and filtering

Because `kubectl` outputs resource names in the same syntax it accepts, you can chain operations using `$()` or `xargs`:

```shell kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service/ ) kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service/ | xargs -i kubectl get '{}' ```

The output might be …(trimmed)

Sources

concepts/workloads/management.md · docManaging Workloads

Related (19)

references Cloud Native Computing Foundation (CNCF)CNCF conf=1
references Manifestmanifests conf=1
part_of Organizing resource configurationsdescribes conf=1
part_of Bulk operations in kubectldescribes conf=1
part_of Updating your application without an outagedescribes conf=1
part_of Canary deploymentsdescribes conf=1
part_of Updating annotationsdescribes conf=1
part_of Scaling your applicationdescribes conf=1
part_of In-place updates of resourcesdescribes conf=1
part_of Disruptive updatesdescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of External toolsdescribes conf=1
part_of Chaining and filteringdescribes conf=1
part_of Recursive operations on local filesdescribes conf=1
part_of Managing rolloutsdescribes conf=1
part_of kubectl applydescribes conf=1
part_of kubectl editdescribes conf=1
part_of kubectl patchdescribes conf=1
api_for Workloaddocuments API object conf=1

← all Docs