×
Community Blog How to Deploy a Container Using GitHub Actions

How to Deploy a Container Using GitHub Actions

This article explains how to deploy a container to Alibaba Cloud Container Service for Kubernetes (ACK) using GitHub Actions.

By Kelvin Galabuzi

What Is GitHub Actions?

GitHub Actions is a continuous integration and delivery (CI/CD) platform used to build, test, and deploy software/applications fast and efficiently.

GitHub Actions provide build and deployment agents (runners), which run on virtual machines that support Linux, Windows, and macOS operating systems. Additionally, you can host your self-hosted runners in a cloud service provider like Alibaba Cloud.

Components of GitHub Actions

  • Workflow: A workflow is a configuration file that processes and runs one or more jobs. Jobs can be run in sequential or parallel order. Workflows are triggered by events in your repository, such as commits, pull requests, etc. Each repository can have more than one workflow configuration file that performs a set of steps required by your application.
  • Events: Events are specific activities in a repository that trigger workflow runs.
  • Jobs: A job is a series of steps executed on the same runner. Steps are performed sequentially and can share data.
  • Runners: Runners are servers that run your GitHub action workflows. Runners can run only one job at a time. Multiple runners are available and run on Ubuntu Linux, Windows, and macOS. If you require a different operating system, you can self-host your runners.
  • Actions: Actions are custom applications that are used to automate repeated tasks. For example, actions reduce repetition when configuring your build and deployment pipeline.

Prerequisites

  • Ensure that you have set up an Alibaba Cloud Container Service for Kubernetes cluster (ACK)
  • You also need to ensure that you have set up an Alibaba Cloud Container registry to host your container images.
  • Set up a GitHub repository containing your Dockerfile, Kubernetes deployment, service, and customized files

Using GitHub Actions to Deploy a Container to ACK

In the following section, we will deploy a container running an NGINX webserver to Alibaba Cloud Container Service for Kubernetes using GitHub Actions. We will use the following sample code for this tutorial.

  • Step 1: Access the GitHub Actions feature under the deployment section using the repo containing your Dockerfile, Kubernetes deployment, service, and customize files. Select the Deploy to Alibaba Cloud ACK action and click Configure:

1
2

  • Step 2: Once you click configure, edit the default workflow configuration file by changing the environment variables to your Alibaba Cloud environment-specific configurations.

Here are some of the parameters you can change:

env:
  REGION_ID: cn-hangzhou
  REGISTRY: registry.cn-hangzhou.aliyuncs.com
  NAMESPACE: namespace
  IMAGE: repo
  ACK_CLUSTER_ID: clusterID
  ACK_DEPLOYMENT_NAME: nginx-deployment

  ACR_EE_REGISTRY: myregistry.cn-hangzhou.cr.aliyuncs.com
  ACR_EE_INSTANCE_ID: instanceID
  ACR_EE_NAMESPACE: namespace
  ACR_EE_IMAGE: repo

3

  • Step 3: Add your Alibaba Cloud environment Access_Key_ID and Access_Key_Secret to your current GitHub repository under Settings:

4

  • Step 4: After you commit to your GitHub repository, it will trigger the workflow file to run. Once it is successful, all the steps within the job will be marked as complete:

5

Finally, you can confirm that the container was successfully deployed by accessing your Kubernetes cluster and running the kubetcl get deployments command:

6

text1

7

0 0 0
Share on

Alibaba Cloud Community

1,044 posts | 257 followers

You may also like

Comments

Alibaba Cloud Community

1,044 posts | 257 followers

Related Products