Code Monkey home page Code Monkey logo

update_awsecr_token_kubernetes's Introduction

update_ecr_token_kubernetes

Presentation

If you are using AWS ECR repository in a kubernetes cluster outside AWS, you will need to update your secret used to connect to AWS ECR few times a day. In fact the token generated by "docker login" will expire every twelve hours. The secret key created initially won't be valid after 12 hours and you won't be able to connect to AWS ECR registry.

To automate the change of the token you can use this Jenkins Pipeline launched as a cron every 6 hours. The Jenkins Pipeline will connect to AWS ECR using a Docker container then use a Kubernetes container to update the secret in Kubernetes.

The role of the pipeline is to change the secret defined in the namespace of the app which use a repository at AWS ECR. AWS credentials are defined via CloudBees plugin: CloudBees Amazon Web Services Credentials Plugin FYI, if kubernetes is hosted in AWS, you just need to enable the permission via IAM.

The pipeline consists of 4 parts:

  • Initialisation of the variables and the trigger (every 6 hours)
  • Create 2 PodTemplate, aws and kubectl and share the docker socket (Using Docker Hub)
  • AWS, connect using the AWS credentials stored in Jenkins and connect using docker client and get the password
  • KUBCETL, update the secret using the password obtained via docker client

How to use

  1. Install and Initialize AWS credentials plugin

In Jenkins, go to "Manage Plugins", then search for the available package and install "CloudBees Amazon Web Services Credentials Plugin"

Once installed, create the credential using your ACCESS KEY ID/PASSWORD.

  1. Create the pipeline

Copy and save the Pipeline below and change the attributes at the beginning of the file:

  • JENKINS_AWS_CREDENTIALS_NAME: the name of the credential created for AWS connection
  • K8s_namespace: Kubernetes namespace where you need to update the secret
  • K8s_keyname: Kubernetes secret used
  • K8s_docker_email: Docker email
  • ECR_repository_url: URL of the AWS ECR repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.