First Kubernetes deployment

👋 Welcome to Octopus Deploy!

This tutorial will walk you through sourcing YAML files from a Git repository, and deploying them to a Kubernetes cluster.

If you’re using Octopus 2024.2 or earlier, please visit the legacy Kubernetes First deployment guide.

Before you start

To follow this tutorial, you need:

  • An Octopus instance. If you don’t already have one, you can start a free trial of Octopus Cloud.
  • A Kubernetes cluster you have terminal access to. If you don’t have one you can install minikube locally.
  • A GitHub account with access to a repository with YAML files to deploy, or you can fork our sample repository below.

GitHub repository

To start quickly, you can fork our sample GitHub repository, which includes pre-created YAML files. Follow the steps below to fork the repository:

  1. Navigate to the OctoPetShop repository.

Sample OctoPetShop GitHub repository

  1. In the top-right corner of the page, click Fork.
  2. Provide an Owner and repository name, for example OctoPetShop.
  3. Keep the Copy the master branch only checkbox selected.
  4. Click Create Fork.
  5. Wait for the process to complete (this should only take a few seconds).

Now you’re ready, let’s begin deploying your first application to Kubernetes.

Log in to Octopus

  1. Log in to your Octopus instance and click New Project.

Get started welcome screen

Add project

Projects let you manage software applications and services, each with their own deployment process.

  1. Give your project a descriptive name, for example, First K8s deployment.

Octopus lets you store your deployment process, settings, and non-sensitive variables in either Octopus or a Git repository.

  1. For this example, keep the default Octopus option selected.
  2. For Deploy to, select the Kubernetes option.
  3. For Manage with, select the YAML files option.
  4. Click Next.

Add new project screen

Add environments

You’ll need an environment to deploy to.

Environments are how you organize your infrastructure into groups representing the different stages of your deployment pipeline. For example, Development, Staging, and Production.

  1. Keep the default environments and click Next.

Environment selection options and deployment lifecycle visuals

Connect Octopus to your Kubernetes cluster

With Octopus Deploy, you can deploy software to:

  • Kubernetes clusters
  • Microsoft Azure
  • AWS
  • Cloud regions
  • Windows servers
  • Linux servers
  • Offline package drop

Regardless of where you’re deploying your software, these machines and services are known as your deployment targets.

  1. Select Yes for Do you have a Kubernetes cluster you can deploy to today?
  2. Click Add Agent.

Connect Octopus to your cluster

Name

  1. Provide a name to identify this cluster in Octopus, for example, K8s Tutorial Cluster.

Environments

For now, we’ll use one cluster for all environments, and use separate namespaces for each. Later, you can add additional clusters and scope them to individual environments.

  1. Select Development, Staging, and Production from the Environments dropdown list.

Target Tags

Octopus uses target tags to select which clusters (known in Octopus as a deployment target) a project should deploy to. Later, you’ll add the same target tag to your deployment process. You can deploy to multiple clusters simply by adding this tag.

  1. Add a new target tag by typing it into the field. For this example, we’ll use tutorial-cluster.

Advanced settings

In Advanced settings, you can provide an optional Kubernetes namespace and Storage class. These are advanced features that you can skip for this tutorial.

  1. Click Next.

Add new Kubernetes Agent dialog

Install NFS CSI Driver

The Kubernetes agent will run as a pod, and will need some resilient storage. For this tutorial we can install the NFS driver, and let the agent provision some shared storage for it to use.

  1. Copy the Helm command and run it in the terminal connected to your target cluster.
  2. Click Next.

Install NFS CSI Driver dialog

Install Kubernetes Agent

Octopus generates a Helm command that you copy and paste into a terminal connected to the target cluster. After it’s executed, Helm installs all the required resources and starts the agent.

  1. Copy the Helm command.
  2. After the NFS Helm command has finished running, paste and run the agent Helm command in the terminal connected to your target cluster.

Install Kubernetes Agent dialog

  1. After the agent has successfully registered and passed the health check, Close the dialog.
  2. Click Next.

Create deployment process

The next step is creating your deployment process. This is where you define the steps that Octopus uses to deploy your software. Based on your project setup, the Deploy Kubernetes YAML deployment step has already been added and partially configured for you.

  1. Click Thanks, got it.

Step Name

You can leave this as the default Deploy Kubernetes YAML.

Target Tags

  1. Octopus pre-selected the target tag you created while configuring the Kubernetes agent ( tutorial-cluster).

Target tags expander with tutorial-cluster tag selected

YAML source

You can source YAML files via 3 methods:

  • Directly from a Git Repository, loaded at deployment time.
  • Contained within a Package, like a ZIP or NuGet file.
  • Inline YAML that you paste directly into the step.

Sourcing from a Git Repository can streamline your deployment process by reducing the steps to get your YAML into Octopus.

  1. Select Git Repository as your YAML source.

YAML source expander where users can select where to source YAML files from

Repository URL

  1. Enter the full URL to the Git repository where you store the YAML files you want to deploy, for example, https://github.com/your-user/OctoPetShop.git

Repository URL expander where the user's YAML files are stored

Git repository details

  1. Select Git credentials and click the + icon to add new credentials.
  2. Enter a name for your Git credential so you can identify it later.
  3. Provide your GitHub username.

A drawer interface where users can configure Git credentials

Generate GitHub personal access token

Github.com now requires token-based authentication (this excludes GitHub Enterprise Server).

Follow the steps below to create a personal access token, or learn more in the GitHub documentation.

  1. Navigate to github.com and log in to your account.
  2. Click your profile picture in the top right corner.
  3. Click Settings.
  4. Scroll down to the bottom of the page and click Developer settings.
  5. Under Personal access tokens, click Fine-grained tokens.
  6. Click Generate new token.
  7. Under Token name, enter a name for the token.
  8. Under Expiration, provide an expiration for the token.
  9. Select a Resource Owner.
  10. Under Repository access, choose Only select repositories and select the OctoPetShop repository from the dropdown.
  11. Click on Repository permissions, scroll down to Contents, and select Read-only.
  12. Scroll down to the Overview, and you should have 2 permissions for one of your repositories (contents and metadata).
  13. Click Generate token and copy the token.

A GitHub settings page where users can manage permissions for fine-grained tokens

Git repository details

  1. Paste the token into Octopus’s personal access token field.
  2. Save your Git credential.

Your new Git credential should now be selected in the Authentication dropdown.

Authentication expander with a Git repository selected

Branch settings

  1. Provide the default branch you want to use. For example, master if you’re using the sample repo.

Branch setting expander where user can configure default branch

File Paths

  1. Enter the relative path(s) to the YAML files you want to deploy to your cluster. If you’re using the sample repo, use k8s/*.yaml to select all YAML files in the k8s root folder.

File paths expander where user can configure path to YAML files

Namespace

  1. Specify the namespace you want to deploy your YAML files into, for example, k8s-tutorial. If the namespace doesn’t exist yet, Octopus will create it during the deployment.

You can skip the other sections of this page for this tutorial.

Save your step and you can move on to create and deploy a release.

Release and deploy

Create release

A release is a snapshot of the deployment process and the associated assets (Git resources, variables, etc.) as they exist when the release is created.

  1. Click the Create Release button.

You’ll see a summary of the Git resources you provided in the Deploy Kubernetes YAML step.

Release summary showing Git resources

  1. Click Save.

Execute deployment

Deployments typically occur in a defined environment order (for example, Development ➜ Staging ➜ Production), starting with the first one. Later you can configure Lifecycles with complex promotion rules to accurately reflect how you want to release software.

  1. Click Deploy to Development to deploy to the development environment associated with your cluster.
  2. Review the preview summary and when you’re ready, click Deploy.

Your first deployment may take slightly longer as we download and extract the necessary tools to run steps.

Watch the deployment complete

The Task Summary tab will show you in real-time how the deployment steps are progressing. You can also view the status of Kubernetes resources being deployed on the cluster itself.

  1. Navigate to the Kubernetes Object Status tab to see the live status of your Kubernetes objects as the deployment progresses.

Kubernetes Object Status dashboard showing a successful deployment

You successfully completed your first deployment to Kubernetes! 🎉

As you continue to explore Octopus Deploy, consider diving deeper into powerful features like variables, joining our Slack community, or checking out our other tutorials to expand your knowledge.

Additional Kubernetes resources

Help us continuously improve

Please let us know if you have any feedback about this page.

Send feedback

Page updated on Thursday, August 29, 2024