Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
Deploy to kubernetes cluster with github workflow

I have setup a kubernetes cluster on AWS using kops.

I am trying to automate deployment with github actions.

name: Build and Deploy

on:
  push:
    branches:
      - develop

jobs:
  build_docker_image:
    - uses: actions/checkout@v2
    - name: Build the tagged Docker image
      run: docker build --target dev -t org/customer-service-backend:la
  push_docker_image_to_github-packages:
    - uses: docker/build-push-action@v2
      with:
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}
        registry: docker.pkg.github.com
        repository: org/customer-service-backend:latest
        tag_with_ref: true
  deploy_to_kubernetes_cluster:
    ... what to do here?

I am able to built the image and push to gihub packages.

I have created deployment.yml in the root directory of the repository.

How can I deploy to kubernetes cluster?

Also, I am tagging the images with latest. Is it fine or I need to use GITHUB_REF for tagging?

Update

I am able to configure all the things. I only need to get kubeconfig to authenticate to existing cluster.

name: Build and Deploy

on:
  push:
    branches:
      - develop

jobs:

  build_docker_image:
    - uses: actions/checkout@v2
    - name: Build the tagged Docker image
      run: docker build --target dev -t org/customer-service-backend:${{ github.sha }}

  push_docker_image_to_github_packages:
    needs: build_docker_image
    - uses: docker/build-push-action@v2
      with:
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}
        registry: docker.pkg.github.com
        repository: org/customer-service-backend:${{ github.sha }}
        tag_with_ref: true

  deploy_to_kubernetes_cluster:
    needs: push_docker_image_to_github_packages
    name: Set Kubernetes Context
    uses: azure/k8s-set-context@v1
      with:
        method: kubeconfig
        kubeconfig: ${{ secrets.KUBE_CONFIG }} # Use secret (https://developer.github.com/actions/managing-workflows/storing-secrets/)
    run: |
      sed -i'' -e 's/IMAGE_LABEL/${{ github.sha }}/g' deployment.yml
      kubectl apply -f deployment.yml



over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

By looking your workflow config file, all the jobs running parallelly.

But, probably it's not what you want.

Pushing image needs a built image and deployment job needs an updated built image.

On Access kubernetes cluster, just access into your cluster and do,

cat $HOME/.kube/config

and copy the output.

Now, create a secret in github with KUBE_CONFIG as environment variable.

Notes - this is one method to access kubernetes cluster, there are other methods as well, choose one that suits your need

name: Build and Deploy

on:
  push:
    branches:
      - develop

jobs:

  build_docker_image:
      name: Build Docker Image
      runs-on: ubuntu-latest
      steps:
        - name: Checkout Repo
          uses: actions/checkout@v2
        - name: Build the tagged Docker image
          run: docker build --target dev -t your_org/customer-service-backend:${{ github.sha }} .

  push_docker_image_to_github_packages:
    name: Push Docker Image to Github Packages
    needs: build_docker_image
    runs-on: ubuntu-latest
    steps:
      - name: Push Docker Image
        uses: docker/build-push-action@v2
        with:
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
          registry: docker.pkg.github.com
          repository: your_org/customer-service-backend:${{ github.sha }}

  deploy_to_kubernetes_cluster:
    name: Deploy to Kubernetes Cluster
    needs: push_docker_image_to_github_packages
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2
      - name: Set Kubernetes Context
        uses: azure/k8s-set-context@v1
        with:
          method: kubeconfig
          kubeconfig: ${{ secrets.KUBE_CONFIG }} # Use secret (https://developer.github.com/actions/managing-workflows/storing-secrets/)
      - name: Deploy to Cluster
        run: |
          sed -i'' -e 's/IMAGE_LABEL/${{ github.sha }}/g' deployment.yml
          kubectl apply -f deployment.yml

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda