導入
この投稿では、Go ベースの Web アプリケーションの DevOpsifying プロセスについて説明します。 Docker を使用したアプリケーションのコンテナ化から、Helm を使用した Kubernetes クラスター (AWS EKS) へのデプロイ、GitHub Actions との継続的インテグレーションのセットアップ、ArgoCD を使用したデプロイの自動化まで、すべてをカバーします。このチュートリアルを終了するまでに、完全に動作する CI/CD 対応の Go Web アプリケーションが完成します。
前提条件
このプロジェクトを開始する前に、次の前提条件を満たしていることを確認してください:
AWS アカウント: Go ベースのアプリケーションをデプロイするための EKS クラスターを作成および管理するには、アクティブな AWS アカウントが必要です。
DockerHub アカウント: Docker イメージをプッシュするには、DockerHub アカウントが必要です。
DevOps の基本知識: CI/CD パイプライン、コンテナ化、オーケストレーション、クラウド展開の理解など、DevOps の概念と実践に精通していることが不可欠です。
Helm: アプリケーションをパッケージ化してデプロイするには、Kubernetes パッケージ マネージャーである Helm の基本的な知識が必要です。
これらの前提条件を満たすことで、このガイドの手順に従って Go ベースのアプリケーションを正常に DevOpsify する準備が整います!
ステップ 1: ソースコードの取得
プロジェクトを開始するには、GitHub リポジトリからソース コードのクローンを作成する必要があります。次のコマンドを使用してプロジェクトのクローンを作成します:
git clone https://github.com/iam-veeramalla/go-web-app-devops.git
このリポジトリには、このガイドで説明されている DevOps プラクティスを使用して Go ベースのアプリケーションをセットアップおよびデプロイするために必要なすべてのファイルと構成が含まれています。クローンを作成したら、以下の手順に進み、その手順に従ってアプリケーションをコンテナ化、デプロイ、管理できます。
ステップ 2: Go Web アプリケーションのコンテナ化
最初のステップは、Go アプリケーションをコンテナ化することです。マルチステージ Dockerfile を使用して Go アプリケーションを構築し、本番環境に対応した軽量のイメージを作成します。
FROM golang:1.22.5 as build WORKDIR /app COPY go.mod . RUN go mod download COPY . . RUN go build -o main . FROM gcr.io/distroless/base WORKDIR /app COPY --from=build /app/main . COPY --from=build /app/static ./static EXPOSE 8080 CMD ["./main"]
Docker イメージをビルドしてプッシュするコマンド:
docker login docker build . -t go-web-app docker push go-web-app:latest
この Dockerfile では、最初のステージで Golang イメージを使用してアプリケーションを構築します。第 2 段階では、ディストリビューションのないベース イメージを使用します。これは、Go アプリケーションを実行するために必要なファイルのみを含む、はるかに小さく安全です。
ステップ 3: AWS EKS を使用して Kubernetes にデプロイする
次に、コンテナ化されたアプリケーションを Kubernetes クラスターにデプロイします。クラスターをセットアップしてアプリをデプロイする方法は次のとおりです。
EKS クラスターを作成します:
eksctl create cluster --name demo-cluster --region us-east-1
デプロイメント構成 (deployment.yaml):
apiVersion: apps/v1 kind: Deployment metadata: name: go-web-app labels: app: go-web-app spec: replicas: 1 selector: matchLabels: app: go-web-app template: metadata: labels: app: go-web-app spec: containers: - name: go-web-app image: iamamash/go-web-app:latest ports: - containerPort: 8080
サービス構成 (service.yaml):
apiVersion: v1 kind: Service metadata: name: go-web-app labels: app: go-web-app spec: ports: - port: 80 targetPort: 8080 protocol: TCP selector: app: go-web-app type: ClusterIP
Ingress 構成 (ingress.yaml):
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: go-web-app annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: ingressClassName: nginx rules: - host: go-web-app.local http: paths: - path: / pathType: Prefix backend: service: name: go-web-app port: number: 80
kubectl を使用して構成を適用します:
kubectl apply -f deployment.yaml kubectl apply -f service.yaml kubectl apply -f ingress.yaml
Nginx Ingress コントローラーのセットアップ:
Kubernetes の Ingress コントローラーは、クラスター内のサービスへの外部アクセスを管理し、通常は HTTP および HTTPS トラフィックを処理します。集中ルーティングを提供し、トラフィックがサービスに到達する方法についてのルールを定義できます。このプロジェクトでは、Nginx Ingress コントローラーを使用して、トラフィックを効率的に管理し、Kubernetes クラスターにデプロイされた Go ベースのアプリケーションにルーティングします。
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.1/deploy/static/provider/aws/deploy.yaml
ステップ 4: Helm を使用したパッケージ化
Kubernetes リソースをより効果的に管理するために、Kubernetes のパッケージ マネージャーである Helm を使用してアプリケーションをパッケージ化します。
Helm チャートを作成します:
helm create go-web-app-chart
チャートを作成した後、テンプレート ディレクトリ内のすべてを、deployment.yaml、service.yaml、および ingress.yaml ファイルに置き換えます。
values.yaml の更新:values.yaml ファイルには、Docker イメージ タグなどの動的な値が含まれます。このタグは GitHub Actions 実行 ID に基づいて自動的に更新され、各デプロイメントが一意であることが保証されます。
# Default values for go-web-app-chart. replicaCount: 1 image: repository: iamamash/Go-Web-App pullPolicy: IfNotPresent tag: "10620920515" # Will be updated by CI/CD pipeline ingress: enabled: false className: "" annotations: {} hosts: - host: chart-example.local paths: - path: / pathType: ImplementationSpecific
Helm デプロイメント:
kubectl delete -f k8s/. helm install go-web-app helm/go-web-app-chart kubectl get all
ステップ 5: GitHub アクションとの継続的統合
アプリケーションのビルドとデプロイを自動化するために、GitHub Actions を使用して CI/CD パイプラインをセットアップしました。
GitHub アクション ワークフロー (.github/workflows/cicd.yaml):
name: CI/CD on: push: branches: - main paths-ignore: - 'helm/**' - 'README.md' jobs: build: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Go 1.22 uses: actions/setup-go@v2 with: go-version: 1.22 - name: Build run: go build -o go-web-app - name: Test run: go test ./... push: runs-on: ubuntu-latest needs: build steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Login to DockerHub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and Push action uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/go-web-app:${{github.run_id}} update-newtag-in-helm-chart: runs-on: ubuntu-latest needs: push steps: - name: Checkout repository uses: actions/checkout@v4 with: token: ${{ secrets.TOKEN }} - name: Update tag in Helm chart run: | sed -i 's/tag: .*/tag: "${{github.run_id}}"/' helm/go-web-app-chart/values.yaml - name: Commit and push changes run: | git config --global user.email "ansari2002ksp@gmail.com" git config --global user.name "Amash Ansari" git add helm/go-web-app-chart/values.yaml git commit -m "Updated tag in Helm chart" git push
To securely store sensitive information like DockerHub credentials and Personal Access Tokens (PAT) in GitHub, you can use GitHub Secrets. To create a secret, navigate to your repository on GitHub, go to Settings > Secrets and variables > Actions > New repository secret. Here, you can add secrets like DOCKERHUB_USERNAME, DOCKERHUB_TOKEN, and TOKEN. Once added, these secrets can be accessed in your GitHub Actions workflows using ${{ secrets.SECRET_NAME }} syntax, ensuring that your sensitive data is securely managed during the CI/CD process.
Step 6: Continuous Deployment with ArgoCD
Finally, we implement continuous deployment using ArgoCD to automatically deploy the application whenever changes are pushed.
Install ArgoCD:
kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}' kubectl get svc argocd-server -n argocd
Setup ArgoCD Project: To access the ArgoCD UI after setting it up, you first need to determine the external IP of the node where ArgoCD is running. You can obtain this by running the command:
kubectl get nodes -o wide
Next, get the port number at which the ArgoCD server is running using:
kubectl get svc argocd-server -n argocd
Once you have the external IP and port number, you can access the ArgoCD UI by navigating to http://
To log in to the ArgoCD UI for the first time, use the default username admin. The password can be retrieved from the ArgoCD secrets using:
kubectl edit secret argocd-initial-admin-secret -n argocd
Copy the encoded password from the data.password field and decode it using base64:
echo <encoded-password> | base64 --decode </encoded-password>
For example, if the encoded password is kjasdfbSNLnlkaW==, decoding it with:
echo kjasdfbSNLnlkaW== | base64 --decode
will provide the actual password. Be sure to exclude any trailing % symbol from the decoded output when using the password to log in.
Now, after accessing the ArgoCD UI, since both ArgoCD and the application are in the same cluster, you can create a project. To do this, click on the "New App" button and fill in the required fields, such as:
- App Name: Provide a name for your application.
- Sync Policy: Choose between manual or automatic synchronization.
- Self-Heal: Enable this option if you want ArgoCD to automatically fix any drift.
- Source Path: Enter the GitHub repository URL where your application code resides.
- Helm Chart Path: Specify the path to the Helm chart within your repository.
- Destination: Set the Cluster URL and namespace where you want the application deployed.
- Helm Values: Select the appropriate values.yaml file for your Helm chart.
After filling in these details, click on "Create" and wait for ArgoCD to create the project. ArgoCD will pick up the Helm chart and deploy the application to the Kubernetes cluster for you. You can verify the deployment using:
kubectl get all
That's all you need to do!
Conclusion
Congratulations! You have successfully DevOpsified your Go web application. This end-to-end guide covered containerizing your application with Docker, deploying it with Kubernetes and Helm, automating builds with GitHub Actions, and setting up continuous deployments with ArgoCD. You are now ready to manage your Go application with full CI/CD capabilities.
Feel free to leave your comments and feedback below! Happy DevOpsifying!
Reference
For a detailed video guide on deploying Go applications on AWS EKS, check out this video.
以上がGo Web アプリケーションの DevOpsifying: エンドツーエンド ガイドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

GO言語で文字列パッケージをマスターすると、テキスト処理機能と開発効率が向上します。 1)コンテナ機能を使用してサブストリングを確認し、2)インデックス関数を使用してサブストリング位置を見つけ、3)関数を効率的にスプライスストリングスライス、4)機能を置き換えてサブストリングを置き換えます。空の文字列や大きな文字列操作のパフォーマンスの問題をチェックしないなど、一般的なエラーを避けるように注意してください。

文字列の操作を簡素化し、コードをより明確かつ効率的にすることができるため、GOの文字列パッケージを気にする必要があります。 1)文字列を使用して、弦を効率的にスプライスするために参加します。 2)文字列を使用して、空白の文字で文字列を分割します。 3)文字列を介してサブストリング位置を見つけます。Indexと文字列lastindex; 4)文字列を使用して、文字列を置き換える。 5)文字列を使用して、ビルダーを効率的にスプライスします。 6)予期しない結果を避けるために、常に入力を確認してください。

theStringspackageIngoisESSENTINEFOREFFSTRINGMANIPULATION.1)ITOFFERSSSIMPLEYETPOWERFULFUNCTIONS FORTOSSCHECKINGSUBSTRINGSNINGSTRINGS.2)ITHANDLESUNICODEWELL、ITHANDLESUNICODEWELL

whendeciding botedego'sbytespackageandstringspackage、usebytes.bufferbinarydataandstrings.builderforstringoperations.1)usebytes.bufferforkithbyteslices、binarydata、appendingdatatypes、およびwritioio.writioio.writioio.writioio.writioio.

Goの文字列パッケージは、さまざまな文字列操作機能を提供します。 1)文字列を使用して、サブストリングを確認します。 2)文字列を使用して、ストリングをサブストリングスライスに分割します。 3)文字列を通して文字列をマージします。 4)文字列または文字列を使用して、文字列の最初と端でブランクまたは指定された文字を削除します。 5)指定されたすべてのサブストリングを文字列に置き換えます。ReplaceAll。 6)文字列を使用して、hasprefixまたは文字列hassuffixを使用して、文字列の接頭辞または接尾辞を確認します。

GO言語文字列パッケージを使用すると、コードの品質が向上します。 1)文字列を使用して()join()を使用して、パフォーマンスのオーバーヘッドを避けるために、文字列アレイをエレガントに接続します。 2)strings.split()とstrings.contains()を組み合わせて、テキストを処理し、ケースの感度の問題に注意を払います。 3)文字列の乱用を避け、replace()を回避し、多数の置換に正規表現を使用することを検討します。 4)文字列を使用して、ビルダーを使用して、頻繁にスプライシング文字列の性能を向上させます。

GoのBYTESパッケージは、バイトスライスを処理するためのさまざまな実用的な機能を提供します。 1.bites.containsは、バイトスライスに特定のシーケンスが含まれているかどうかを確認するために使用されます。 2.bites.splitは、バイトスライスをスモールピースに分割するために使用されます。 3.bites.joinは、複数のバイトスライスを1つに連結するために使用されます。 4.bites.trimspaceは、バイトスライスのフロントブランクとバックブランクを削除するために使用されます。 5.バイト。エクアルは、2つのバイトスライスが等しいかどうかを比較するために使用されます。 6.bytes.indexは、大規模なスライスでサブスライスの開始インデックスを見つけるために使用されます。

エンコード/binaryPackageIngoisESSENTINESTENTINESTINESTIDANDARDIZEDWAIDTOREADANDWRITEBINIRYDATA、クロスプラットフォームコンパティビティアンドハンドリングの可能性を確保することを確認します


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

Dreamweaver Mac版
ビジュアル Web 開発ツール

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

ドリームウィーバー CS6
ビジュアル Web 開発ツール
