简体   繁体   English

使用 Jenkins 管道无法识别 aws eks 命令

[英]aws eks command not recognized using Jenkins pipeline

I have created a EC2 instance where Jenkins is running connected to my GitHub account.我创建了一个 EC2 实例,其中 Jenkins 正在运行,连接到我的 GitHub 帐户。 The following are the two steps of my Jenkins pipeline:以下是我的 Jenkins 管道的两个步骤:

pipeline {
    agent any
    stages {
        stage('Kubernetes cluster') {
            steps {
                withAWS(region:'us-west-2', credentials:'aws-kubernetes') {
                    sh '''
                    if [ ! aws cloudformation describe-stacks --region us-west-2 --stack-name eksctl-EmaJarK8sCluster-cluster ] ; then

                        if [ ! aws cloudformation describe-stacks --region us-west-2 --stack-name eksctl-EmaJarK8sCluster-nodegroup-standard-workers ] ; then

                            eksctl create cluster \
                            --name EmaJarK8sCluster \
                            --version 1.13 \
                            --nodegroup-name standard-workers \
                            --node-type t2.small \
                            --nodes 2 \
                            --nodes-min 1 \
                            --nodes-max 3 \
                            --node-ami auto \
                            --region us-west-2 \
                            --zones us-west-2a \
                            --zones us-west-2b \
                            --zones us-west-2c \

                        fi

                    fi
                    '''
                }
            }
        }

        stage('Configuration file cluster') {
            steps {
                withAWS(region:'us-west-2', credentials:'aws-kubernetes') {
                    sh '''
                        aws eks --region us-west-2 update-kubeconfig --name EmaJarK8sCluster
                    '''
                }
            }
        }
    }
}

The first step creates a Kubernetes cluster if it doesn't exist, the second one creates a configuration file for that cluster.第一步创建一个 Kubernetes 集群,如果它不存在,第二步为该集群创建一个配置文件。 This step works pretty well and creates two cloudformation stacks and one EC2 machine where the Kubernetes cluster is running.此步骤运行良好,并创建了两个 cloudformation 堆栈和一台运行 Kubernetes 集群的 EC2 机器。

The second stage fails with the following error:第二阶段失败并出现以下错误:

Invalid choice: 'eks', maybe you meant:

  * es

After reading a couple of tutorial I've found out that I needed to update awscli to version 1.18.57 in order to have the eks command available.在阅读了一些教程后,我发现我需要将awscli更新到版本1.18.57才能使用eks命令。 So I've logged into my Jenkins machine (not the one dedicated to the k8s cluster) ad I've update the awscli .所以我已经登录到我的 Jenkins 机器(不是专用于 k8s 集群的机器)并更新了awscli Unfortunately this is not enough.不幸的是,这还不够。 I still get the same error.我仍然得到同样的错误。 I can run the command manually into Jenkins the machine but, for some reason, I cannot run it via Jenkins pipeline.我可以手动将命令运行到机器 Jenkins 中,但由于某种原因,我无法通过 Jenkins 管道运行它。

Can someone help me with this problem?有人可以帮我解决这个问题吗?

Thanks in advance.提前致谢。

Can you provide the full path to the aws command?您能否提供aws命令的完整路径? Also add which aws and aws --version to the second stage script, and confirm that output.还将which awsaws --version添加到第二阶段脚本,并确认 output。

The above should highlight the actual path of the command, and the current version.上面应该突出显示命令的实际路径和当前版本。 Correct your configuration as needed.根据需要更正您的配置。

Are you updated jenkins agents?您是否更新jenkins代理?

If not:如果不:

Upgrading Windows Service Wrapper 升级 Windows 服务包装器

  1. Upgrade Jenkins to the version, which provides this module升级 Jenkins 到提供该模块的版本
  2. Jenkins is expected to automatically upgrade jenkins-slave.exe executables Jenkins 有望自动升级jenkins-slave.exe可执行文件
  3. If the upgrade happens, you should be able to see the message in the Agent log in Jenkins Web UI如果发生升级,您应该能够在 Jenkins Web UI 的Agent log中看到消息
  4. Once upgrade is done, the changes will be applied on the next Windows service restart升级完成后,更改将应用于下一次 Windows 服务重启

Unfortunately the solutions provided didn't work for me.不幸的是,提供的解决方案对我不起作用。 My goal was to setup an machine where I could run a Kubernetes environment in order to implement a blue/green deployment.我的目标是设置一台可以运行 Kubernetes 环境的机器,以实现蓝/绿部署。 The deployment had to be handled using Jenkins so I had to create a dedicated machine for Jenkins itself.必须使用 Jenkins 处理部署,因此我必须为 Jenkins 本身创建一个专用机器。

I followed this guide to set up all the dependencies: https://medium.com/faun/learning-kubernetes-by-doing-part-1-setting-up-eks-in-aws-50dcf7a76247我按照本指南设置了所有依赖项: https://medium.com/faun/learning-kubernetes-by-doing-part-1-setting-up-eks-in-aws-50dcf7a76247

The mistake that I made before was to install all those dependencies using brew .我之前犯的错误是使用brew安装所有这些依赖项。 This caused many problems and polluted my PATH environment variable.这导致了很多问题并污染了我的 PATH 环境变量。 I solved it terminating the machine and creating a new instance.我解决了它终止机器并创建一个新实例。 In this case I installed the dependencies manually or using apt-get.在这种情况下,我手动或使用 apt-get 安装了依赖项。

The resources I had to install:我必须安装的资源:

  • AWS CLI AWS CLI
  • IAM-AWS-AUTHENTICATOR IAM-AWS-AUTHENTICATOR
  • Docker Docker
  • eksctl eksctl

A couple of notes:几点注意事项:

  • Be sure to install eksctl version 0.19.0 as reported here确保安装 eksctl 版本 0.19.0,如此所述
  • If you get the error "aws-iam-authenticator": executable file not found in $PATH be sure to install aws-iam-authenticator following this guide如果您收到错误"aws-iam-authenticator": executable file not found in $PATH ,请务必按照指南安装aws-iam-authenticator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM