찾다
백엔드 개발GolangGo 웹 애플리케이션 DevOpsifying: 엔드투엔드 가이드

소개

이번 게시물에서는 Go 기반 웹 애플리케이션을 DevOpsifying하는 과정을 안내해 드리겠습니다. Docker를 사용한 애플리케이션 컨테이너화부터 Helm을 사용하여 Kubernetes 클러스터(AWS EKS)에 배포, GitHub Actions와의 지속적인 통합 설정, ArgoCD를 사용한 배포 자동화에 이르기까지 모든 것을 다룹니다. 이 튜토리얼이 끝나면 완벽하게 작동하는 CI/CD 지원 Go 웹 애플리케이션을 갖게 됩니다.

전제 조건

이 프로젝트를 시작하기 전에 다음 전제 조건을 충족하는지 확인하세요.

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 웹 애플리케이션 컨테이너화

첫 번째 단계는 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 이미지를 사용하여 애플리케이션을 빌드합니다. 두 번째 단계에서는 Go 애플리케이션을 실행하는 데 필요한 파일만 포함되어 훨씬 더 작고 더 안전한 distroless 기본 이미지를 사용합니다.

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.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 수신 컨트롤러 설정:

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 create go-web-app-chart

차트를 생성한 후 템플릿 디렉터리 내부의 모든 항목을 배포.yaml, service.yaml 및 ingress.yaml 파일로 바꿉니다.

values.yaml 업데이트: value.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

헬름 배포:

kubectl delete -f k8s/.
helm install go-web-app helm/go-web-app-chart
kubectl get all

5단계: GitHub Actions와의 지속적인 통합

애플리케이션 빌드 및 배포를 자동화하기 위해 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://:. For example, if the external IP is 54.161.25.151 and the port number is 30498, the URL to access ArgoCD UI would be http://54.161.25.151:30498.

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.

DevOpsifying a Go Web Application: An End-to-End Guide

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 웹 애플리케이션 DevOpsifying: 엔드투엔드 가이드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
GO의 문자열 조작 : '문자열'패키지 마스터 링GO의 문자열 조작 : '문자열'패키지 마스터 링May 14, 2025 am 12:19 AM

GO 언어로 문자열 패키지를 마스터하면 텍스트 처리 기능과 개발 효율성이 향상 될 수 있습니다. 1) 함유 기능을 사용하여 하위 문자열을 확인하십시오. 2) 인덱스 기능을 사용하여 하위 문자열 위치를 찾으십시오. 빈 문자열을 확인하지 않고 큰 문자열 작동 성능 문제와 같은 일반적인 오류를 피하기 위해주의하십시오.

'문자열'패키지 팁과 요령으로 이동하십시오'문자열'패키지 팁과 요령으로 이동하십시오May 14, 2025 am 12:18 AM

문자열 조작을 단순화하고 코드를보다 명확하고 효율적으로 만들 수 있기 때문에 이동중인 문자열 패키지에주의해야합니다. 1) strings.join을 사용하여 줄을 효율적으로 스플 라이스; 2) strings.fields를 사용하여 빈 문자로 문자열을 나눕니다. 3) 문자열을 통해 기판 위치를 찾으십시오. 4) 문자열을 대체하려면 strings.replaceall을 사용하십시오. 5) 현악기를 효율적으로 스플 라이스로 사용하여 strings.builder를 사용하십시오. 6) 예상치 못한 결과를 피하기 위해 항상 입력을 확인하십시오.

'문자열'패키지의 이동 : 문자열 작업을위한 이동'문자열'패키지의 이동 : 문자열 작업을위한 이동May 14, 2025 am 12:17 AM

thestringspackageoisessentialponderfficientstringmanipulation.1) itofferssimpleyetpowerfultionsfortaskslikecheckingsubstringsandjoiningstrings.2) ithandlesunicodewell, withFunctionsLikestrings.fieldsforwhitespace-separatedValues.3) forperformance, st

바이트 패키지 대 스트링 패키지로 이동하십시오 : 어떤 사용해야합니까?바이트 패키지 대 스트링 패키지로 이동하십시오 : 어떤 사용해야합니까?May 14, 2025 am 12:12 AM

whendecidingbetweengo'sbytespackageandstringspackage, usebytes.bufferforbinarydataandstrings.builderfortringoperations.1) audeBytes.bufferforworkingwhithbyteslices, binarydata, 첨부 DifferentDatatypes, andwritingtoio.2) useastrons

'문자열'패키지를 사용하여 단계별로 문자열을 조작하는 방법'문자열'패키지를 사용하여 단계별로 문자열을 조작하는 방법May 13, 2025 am 12:12 AM

GO의 문자열 패키지는 다양한 문자열 조작 기능을 제공합니다. 1) 문자열을 사용하여 기판을 확인하십시오. 2) strings.split을 사용하여 문자열을 서브 스트링 슬라이스로 분할하십시오. 3) 문자열을 통해 문자열을 병합합니다. 4) 문자열의 시작과 끝에서 strings.trimspace 또는 strings.trim을 사용하여 공백 또는 지정된 문자를 제거하십시오. 5) 지정된 모든 하위 문구를 문자열로 교체하십시오. 6) strings.hasprefix 또는 strings.hassuffix를 사용하여 문자열의 접두사 또는 접미사를 확인하십시오.

Go Strings 패키지 : 코드를 개선하는 방법?Go Strings 패키지 : 코드를 개선하는 방법?May 13, 2025 am 12:10 AM

Go Language Strings 패키지를 사용하면 코드 품질이 향상 될 수 있습니다. 1) strings.join ()을 사용하여 성능 오버 헤드를 피하기 위해 문자열 배열을 우아하게 연결하십시오. 2) strings.split () 및 strings.contains ()를 결합하여 텍스트를 처리하고 사례 민감도 문제에주의를 기울입니다. 3) 문자열의 남용을 피하고 ()을 replace ()하고 많은 수의 대체에 정규 표현식을 사용하는 것을 고려하십시오. 4) strings.builder를 사용하여 자주 스 플라이 싱 스트링의 성능을 향상시킵니다.

Go Bytes 패키지에서 가장 유용한 기능은 무엇입니까?Go Bytes 패키지에서 가장 유용한 기능은 무엇입니까?May 13, 2025 am 12:09 AM

GO의 바이트 패키지는 바이트 슬라이싱을 처리하기위한 다양한 실용적인 기능을 제공합니다. 1. BYTES는 바이트 슬라이스에 특정 시퀀스가 ​​포함되어 있는지 확인하는 데 사용됩니다. 2.Bytes.split은 바이트 슬라이스를 작은 피스로 분할하는 데 사용됩니다. 3.Bytes.join은 여러 바이트 슬라이스를 하나로 연결하는 데 사용됩니다. 4.bytes.trimspace는 바이트 슬라이스의 전면 및 후면 블랭크를 제거하는 데 사용됩니다. 5.Bytes.equal은 두 바이트 슬라이스가 동일인지 비교하는 데 사용됩니다. 6.bytes.index는 LargersLices에서 하위 슬라이스의 시작 지수를 찾는 데 사용됩니다.

GO의 '인코딩/바이너리'패키지로 바이너리 데이터 처리 마스터 링 : 포괄적 인 가이드GO의 '인코딩/바이너리'패키지로 바이너리 데이터 처리 마스터 링 : 포괄적 인 가이드May 13, 2025 am 12:07 AM

Theencoding/BinaryPackageInsentialBecauseItProvideAstandAdizedWayStandwriteBinaryData, Cross-PlatformCompatibility 및 HandshandlingDifferentendianness.ItoffersFunctionsLikeRead, Write, andwriteUvarIntForPrecisControloverbinary

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

mPDF

mPDF

mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구