⎈ k8s knowledge compiler

Perform a Rolling Update on a DaemonSet [page]deterministic

tasks

This page shows how to perform a rolling update on a DaemonSet.

##

## DaemonSet Update Strategy

DaemonSet has two update strategy types:

* `OnDelete`: With `OnDelete` update strategy, after you update a DaemonSet template, new DaemonSet pods will *only* be created when you manually delete old DaemonSet pods. This is the same behavior of DaemonSet in Kubernetes version 1.5 or before. * `RollingUpdate`: This is the default update strategy. With `RollingUpdate` update strategy, after you update a DaemonSet template, old DaemonSet pods will be killed, and new DaemonSet pods will be created automatically, in a controlled fashion. At most one pod of the DaemonSet will be running on each node during the whole update process.

## Performing a Rolling Update

To enable the rolling update feature of a DaemonSet, you must set its `.spec.updateStrategy.type` to `RollingUpdate`.

You may want to set [`.spec.updateStrategy.rollingUpdate.maxUnavailable`](/docs/reference/kubernetes-api/workload-resources/daemon-set-v1/#DaemonSetSpec) (default to 1), [`.spec.minReadySeconds`](/docs/reference/kubernetes-api/workload-resources/daemon-set-v1/#DaemonSetSpec) (default to 0) and [`.spec.updateStrategy.rollingUpdate.maxSurge`](/docs/reference/kubernetes-api/workload-resources/daemon-set-v1/#DaemonSetSpec) (defaults to 0) as well.

### Creating a DaemonSet with `RollingUpdate` update strategy

This YAML file specifies a DaemonSet with an update strategy as 'RollingUpdate'

After verifying the update strategy of the DaemonSet manifest, create the DaemonSet:

```shell kubectl create -f https://k8s.io/examples/controllers/fluentd-daemonset.yaml ```

Alternatively, use `kubectl apply` to create the same DaemonSet if you plan to update the DaemonSet with `kubectl apply`.

```shell kubectl apply -f https://k8s.io/examples/controllers/fluentd-daemonset.yaml ```

### Checking DaemonSet `RollingUpdate` update strategy

Check the update strategy of your DaemonSet, and make sure it's set to `RollingUpdate`:

```shell kubectl get ds/fluentd-elasticsearch -o go-template='{{.spec.updateStrategy.type}}{{"\n"}}' -n kube-system ```

If you haven't created the DaemonSet in the system, check your DaemonSet manifest with the following command instead:

```shell kubectl apply -f https://k8s.io/examples/controllers/fluentd-daemonset.yaml --dry-run=client -o go-template='{{.spec.updateStrategy.type}}{{"\n"}}' ```

The output from both commands should be:

``` RollingUpdate ```

If the output isn't `RollingUpdate`, go back and modify the DaemonSet object or manifest accordingly.

### Updating a DaemonSet template

Any updates to a `RollingUpdate` DaemonSet `.spec.template` will trigger a rolling update. Let's update the DaemonSet by applying a new YAML file. This can be done with several different `kubectl` commands.

#### Declarative commands

If you update DaemonSets using [configuration files](/docs/tasks/manage-kubernetes-objects/declarative-config/), use `kubectl apply`:

```shell kubectl apply -f https://k8s.io/examples/controllers/fluentd-daemonset-update.yaml ```

#### Imperative commands

If you update DaemonSets using [imperative commands](/docs/tasks/manage-kubernetes-objects/imperative-command/), use `kubectl edit` :

```shell kubectl edit ds/fluentd-elasticsearch -n kube-system ```

##### Updating only the container image

If you only need to update the container image in the DaemonSet template, i.e. `.spec.template.spec.containers[*].image`, use `kubectl set image`:

```shell kubectl set image ds/fluentd-elasticsearch fluentd-elasticsearch=quay.io/fluentd_elasticsearch/fluentd:v2.6.0 -n kube-system ```

### Watching the rolling update status

Finally, watch the rollout status of the latest DaemonSet rolling update:

```shell kubectl rollout status ds/fluentd-elasticsearch -n kube-system ```

When the rollout is complete, the output is similar to this:

```shell daemonset "fluentd-elasticsearch" successfully rolled out ```

## Tro …(trimmed)

Sources

tasks/manage-daemon/update-daemon-set.md · docPerform a Rolling Update on a DaemonSet

Related (12)

part_of {{% heading "prerequisites" %}}describes conf=1
part_of DaemonSet Update Strategydescribes conf=1
part_of Performing a rolling updatedescribes conf=1
part_of Troubleshootingdescribes conf=1
part_of Clean updescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Updating a DaemonSet templatedescribes conf=1
part_of Watching the rolling update statusdescribes conf=1
part_of DaemonSet rolling update is stuckdescribes conf=1
api_for DaemonSetdocuments API object conf=1

← all Docs