AWS EKS (Kubernetes) にデプロイする

The following guide shows how to deploy your application to AWS Elastic Kubernetes Service (EKS) Cluster using the aws-eks-kubectl-run pipe and Bitbucket Pipelines.

Bitbucket Pipelines を使用して、Docker イメージを作成し、コンテナ レジストリ (Docker Hub) にプッシュします。また、Kubernetes へのデプロイを自動化する設定の方法についても説明します。

前提条件

To deploy your application with aws-eks-kubectl-run pipe you’ll need to have:

  • アプリケーションへのデプロイや AWS EKS クラスタへの更新のアップロードをパイプに許可するための十分な権限が構成されている IAM ユーザー。

  • An AWS EKS cluster configured for the application: Getting Started with eksctl.

  • You have configured a Worker Node Group. Here is a simple tutorial from AWS: Creating the Amazon EKS Worker Node IAM Role.

  • イメージのプッシュおよびプルが可能な DockerHub アカウント。

手順

1. Bitbucket リポジトリを構成します。

2. Add your credentials and configuration settings in Bitbucket as variables. See: how to configure Pipelines variables.

変数名

DOCKERHUB_USERNAME

Dockerhub ユーザー名

DOCKERHUB_PASSWORD

DockerHub パスワード

AWS_ACCESS_KEY_ID

AWS アクセス キー

AWS_SECRET_ACCESS_KEY

AWS 秘密アクセス キー。セキュアな変数として保存されている必要があります。

AWS_DEFAULT_REGION

The AWS region code (us-east-1, us-west-2, etc.) of the region containing the AWS resources. For more information, see Regions and Endpoints.

 

3. bitbucket-pipelines.yml ファイルを編集して、CI/CD 構成をセットアップします

 

image: atlassian/default-image:2 pipelines: default: - step: name: "Build and push" services: - docker script: - IMAGE="bitbucketpipelines/hello-app-eks" - VERSION="${BITBUCKET_BUILD_NUMBER}" - echo ${DOCKERHUB_PASSWORD} | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin - docker build -t ${IMAGE} . - docker tag ${IMAGE} ${IMAGE}:${VERSION} - docker push ${IMAGE} - step: name: "Deploy to PROD" deployment: production script: - envsubst < helloweb-deployment.tpl.yaml > helloweb-deployment.yaml - pipe: atlassian/aws-eks-kubectl-run:1.2.0 variables: AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} AWS_DEFAULT_REGION: "us-east-2" CLUSTER_NAME: "hello-cluster" KUBECTL_COMMAND: "apply" RESOURCE_PATH: "helloweb-deployment.yaml" DEBUG: "true"

This configuration allows you to build and push the image to Docker Hub, then use deployments with the aws-eks-kubectl-run pipe in order to automate deployments to Kubernetes. Learn more about how to edit and configure your Bitbucket pipelines configuration.

4. アプリケーションを本番環境にデプロイします。アプリケーションのコードを Bitbucket リポジトリにプッシュし、それによってパイプラインをトリガーします。[Pipelines] を選択してパイプラインの進行状況をチェックし、アプリケーションが正常にデプロイされたことを確認できます。

aws-eks-kubectl-run pipe can be used with other pipes to create your great CI/CD pipelines.

A full end-to-end example is available in this example repository, you can check it for more details about how to deploy to AWS EKS using Pipelines and Pipes.

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。