Update stateless workloads

You can roll out updates to a Deployment object's pod specification, such as its image, resource usage, requests, or configuration.

To update the Deployment object, apply a new or updated manifest file to it. Update a deployment to scale or specify a new version of your application.

Before you begin

To run commands against a user cluster, use the gdcloud CLI to access its kubeconfig file.

  1. Ensure that you have downloaded, installed, and configured the gdcloud CLI.

  2. Run gdcloud auth login to log in to the org admin cluster.

  3. Locate the user cluster name, or ask your Platform Administrator what the cluster name is.

  4. To generate the kubeconfig file of the user cluster, run:

    gdcloud clusters get-credentials USER_CLUSTER_NAME
    
  5. Record the path to the generated file, such as /tmp/user-cluster-kubeconfig-with-user-identity.yaml.

  6. Use the path to replace USER_CLUSTER_KUBECONFIG in these instructions.

To get the required permissions to update stateless workloads, ask your Organization IAM Admin to grant you the Namespace Admin role.

Update the deployment

To update a Deployment object, run:

kubectl --kubeconfig USER_CLUSTER_KUBECONFIG \
    apply -f DEPLOYMENT_FILE

Replace the following:

  • USER_CLUSTER_KUBECONFIG: the kubeconfig file for the user cluster running the deployment.

  • DEPLOYMENT_FILE: the name of the Deployment manifest file to update.

The kubectl apply command applies a manifest file to a resource. If the specified resource does not exist, it is created by the command.

There are also several other ways to update resources within your deployment.

Update a container image

To change the image of a Deployment object, run:

kubectl --kubeconfig USER_CLUSTER_KUBECONFIG set image \
    deployment DEPLOYMENT_NAME \
    IMAGE=IMAGE:TAG

Replace the following:

  • USER_CLUSTER_KUBECONFIG: the kubeconfig file for the user cluster running the deployment.

  • DEPLOYMENT_NAME: the name of the Deployment object containing the image.

  • IMAGE: the name of the container image.

  • TAG: the tag to update for the container image.

Updating the image of a deployment is useful to change selector fields or resources, such as requests or limits.

For example, to update a Deployment object named nginx to use version 1.9.1, run:

kubectl --kubeconfig /tmp/kubeconfig.yaml set image \
    deployment nginx \
    nginx=nginx:1.9.1

Roll back an update

If you want to roll back an update, such as when your deployment becomes unstable, use the kubectl CLI. A Deployment object's rollout history is preserved in the system so you can roll back at any time.

To roll back an in-progress or completed update to its previous revision, run:

kubectl --kubeconfig USER_CLUSTER_KUBECONFIG\
    rollout undo deployment DEPLOYMENT_NAME

Replace the following:

  • USER_CLUSTER_KUBECONFIG: the kubeconfig file for the user cluster running the deployment.

  • DEPLOYMENT_NAME: the name of the Deployment object to roll back.

To roll back to a specific revision, run:

kubectl --kubeconfig USER_CLUSTER_KUBECONFIG \
    rollout undo deployment DEPLOYMENT_NAME \
    --to-revision=REVISION_NUMBER

Replace the following:

  • USER_CLUSTER_KUBECONFIG: the kubeconfig file for the user cluster running the deployment.

  • DEPLOYMENT_NAME: the name of the Deployment object to roll back.

  • REVISION_NUMBER: the integer that defines the revision to roll back to, such as 3.