Deploying to a Kubernetes Cluster

Learn how to create a pipeline to deploy artifacts to a Container Engine for Kubernetes (OKE) cluster.

Before you create the pipeline, you must have a DevOps project, Kubernetes cluster environment to deploy to, and artifacts. Artifacts can be defined inline or located in the Artifact Registry.

DevOps supports deployment of helm charts to OKE cluster. The charts must be located in the OCI Container Registry repository. See Adding a Helm Chart.

To deploy to an OKE cluster using the Blue-Green release strategy, see Blue-Green OKE Deployment and using the Canary strategy, see Canary OKE Deployment.

Required IAM Policy

Each service in Oracle Cloud Infrastructure (OCI) integrates with Identity and Access Management (IAM) for authentication and authorization. To grant users permission to access the DevOps deployment pipelines and other resources, you have to create dynamic groups and IAM policies.

For creating dynamic groups and policies for deployment pipelines, see Deployment Pipeline Policies. For more details, see DevOps IAM Policies.

For accessing DevOps using the Oracle Cloud Console, REST API, and CLI, see Accessing DevOps.

Using the Console

  1. Open the navigation menu and click Developer Services. Under DevOps, click Projects.
  2. Select a project, and click Create pipeline.
  3. Enter a name and optional description for the pipeline.
  4. For Pipeline type, select Create a deployment pipeline.
  5. Click Create pipeline.
  6. To add a stage to the pipeline, click the + icon and select Add stage.
  7. For stage type, select Deploy - OKE, and then click Next.
  8. Enter a name and optional description for the stage.
  9. For Environment, select an existing cluster environment.
  10. Click Select Artifact, and then select one or more artifact resources from your DevOps project.

    The DevOps service performs a Kubernetes server-side apply of the Kubernetes manifest artifacts in the order that they appear in the Console. You can also remove artifacts to select another one or reorder the artifacts list. Removing an artifact in the pipeline stage does not delete the artifact resource from your project. For more information on Kubernetes server-side apply, see Server-Side Apply.

  11. (Optional) To override the default environment namespace, enter value for Override Kubernetes namespace.
  12. To automatically roll back the release stage if the validation fails, select Yes for automatic rollback. If the stage fails, automatic rollback deploys the last successful release version. For more information, see Rolling Back a Deployment.
  13. (Optional) To add tags to the pipeline, click Show tagging options. Tagging is a metadata system that lets you organize and track the resources in your tenancy.

    If you have permissions to create a resource, you also have permissions to add free-form tags to it.

    To add a defined tag, you must have permissions to use the tag namespace.

    For more information, see Resource Tags.

  14. To add the stage to the pipeline, click Add.

    A stage preview provides a snapshot of the configuration.

  15. Add more stages sequentially or in parallel to the pipeline, as needed.
To deploy the build output to the target environment, run the deployment pipeline.

To automatically trigger a deployment from the build pipeline, you can add a Trigger Deployment stage to the build pipeline.

Using the CLI

To create a deployment pipeline, run the create command:

oci devops deploy-pipeline create --project-id

To create a Kubernetes cluster stage for the pipeline, run the create-deploy-oke-stage command:

oci devops deploy-stage create-deploy-oke-stage

Required parameters for the create-deploy-oke-stage command:

  • --kubernetes-manifest-artifact-ids
  • --oke-cluster-environment-id
  • --pipeline-id
  • --stage-predecessor-collection

To get all the commands for deploy-pipeline and deploy-stage:

oci devops deploy-pipeline -h
oci devops deploy-stage -h

To get help for the create-deploy-oke-stage command:

oci devops deploy-stage create-deploy-oke-stage -h

Using the API

To create a deployment pipeline, use the CreateDeployPipeline operation.

To create a Kubernetes cluster stage for the pipeline, use the CreateDeployStage operation. For the deployStageType attribute, specify the OKE_DEPLOYMENT and RUN_OKE_JOB values.

Changing the Predecessor and Successor of a Stage

As you add stages to build the pipeline, a directed acyclic graph (DAG) of the stages is displayed. The graph shows all the linked stages in the pipeline that are eligible to run. At least one of the stages of the pipeline must be declared as a predecessor, which indicates that the stage is eligible to run immediately when the deployment begins. A pipeline can also be specified as the predecessor of a stage when it does not have a preceding stage. Furthermore, stages can have successors.

To modify the predecessor of a stage, follow these steps:

  1. In the graph, click the Menu icon in the top-right corner of the stage that you want to edit.
  2. Select Modify Predecessors.
  3. Select the stage that you want to mark as the predecessor, and click Save.

To modify the successor of a stage, follow these steps:

  1. In the graph, click the Menu icon in the top-right corner of the stage that you want to edit.
  2. Select Modify Successors.
  3. Select the stage that you want to mark as the successor, and click Save.