How to install python in Jenkins deployed in EKS

Viewed 37

We are moving EC2-backed Jenkins to Amazon EKS[Elastic Kubernetes Service] & EFS[Elastic File System] backed Jenkins. I have deployed Jenkins in EKS machine and it's opening and working fine. But to run our pipeline we need to install Python and AWS CLI in the slave node. But we don't know where and how to install them. Any help would be highly appreciated.

enter image description here

3 Answers

Simply create a new Docker image with all the dependencies you need and push it to ECR or any other Registry and use that image.

You can get the publicly available image and include it in your pipeline.

This how I run it on my jenkins

pipeline {
    options {
      ansiColor('xterm')
  }
    environment {

    }
    agent {
        kubernetes {
          yaml '''
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:v1.9.0-debug
    resources:
      requests:
        cpu: 500m
        memory: 512Mi
    limits:
        cpu: 1000m
        memory: 2048Mi
    command:
    - cat
    tty: true
  - name: aws-cli
    image: public.ecr.aws/bitnami/aws-cli:2.4.25
    resources:
      requests:
        cpu: 200m
        memory: 400Mi
      limits:
        cpu: 1024m
        memory: 2048Mi
    command:
    - cat
    tty: true
  securityContext:
    runAsUser: 0
    fsGroup: 0
'''
        }
    }
    stages {
      stage ('GitLab') {
        steps {
        echo 'Building....'
                updateGitlabCommitStatus name: 'build', state: 'running'
        }
      }
      stage ('Configure AWS Credentials') {
          steps {
              withCredentials([[
              $class: 'AmazonWebServicesCredentialsBinding',
              accessKeyVariable: 'AWS_ACCESS_KEY_ID',
              credentialsId: AWSCRED,  // ID of credentials in Jenkins
              secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'

              ]]){
              container('aws-cli') {
                  sh '''
                  ls -lha
                  aws sts get-caller-identity
                  '''
                  }
              }
          }
          post{
            success{
              echo "==== IAM Role assumed successfully ===="
            }
            failure{
              echo "==== IAM Role failed to be assumed ===="
            }
          }
      }
...

As ycr mentioned, I have created my own custom image using the base slave image. I also followed the documentation provided by Jenkins Link. My Custom Docker image:

FROM jenkins/inbound-agent:4.11.2-4
USER root
RUN apt-get update && apt-get install python3-pip toilet curl awscli jq  -y && pip install --upgrade pip
RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz \
  && tar xzvf docker-20.10.9.tgz \
  && mv docker/docker /usr/local/bin \
  && rm -r docker docker-20.10.9.tgz
RUN pip install boto3 pyaml
RUN apt install amazon-ecr-credential-helper -y
COPY . /.

Here I have created .docker folder which contains the config.json file which I'm copying to the root directory of Jenkins slave. It is required if we don't want to provide ECR credentials every time. More details about ECR Credential helper is in this Link

Related