【发布时间】:2020-11-22 21:07:33
【问题描述】:
即使我已经将 CodeBuild IAM 角色添加到 aws-auth.yaml,但我在尝试部署到 EKS 集群时仍遇到以下错误消息
- rolearn: arn:aws:iam::<AWS_ACCOUNT_ID>:role/codebuild-eks
username: codebuild-eks
groups:
- system:masters
错误:无法识别“deployment.yml”:获取 http://localhost:8080/api?timeout=32s: 拨打tcp 127.0.0.1:8080: 连接:连接被拒绝
这是我的代码构建命令:
version: 0.2
phases:
install:
commands:
- curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.11.10/2019-06-21/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
- kubectl version --short --client
- curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
- chmod +x ./aws-iam-authenticator
- mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$HOME/bin:$PATH
- aws-iam-authenticator help
pre_build:
commands:
- echo Entered the pre_build phase...
- echo Logging in to Amazon EKS...
- mkdir -p ~/.kube
- aws s3 cp s3://ppshein-eks/config ~/.kube/config
- export KUBECONFIG=$KUBECONFIG:~/.kube/config
- aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $AWS_CLUSTER_NAME
build:
commands:
- echo Entered the build phase...
- echo Change directory to secondary source
- cd $CODEBUILD_SRC_DIR
- echo List directory
- ls -la
- kubectl get pods --kubeconfig ~/.kube/config
- kubectl apply -f deployment.yml
问题是当 CodeBuild 运行此 kubectl apply -f deployment.yml 语句时,我收到错误消息,但上面的 kubectl get pods --kubeconfig ~/.kube/config 运行正常。
请告诉我我错过了添加或配置的区域。谢谢。
【问题讨论】:
-
我不是 CodeBuild 专家,但看起来这些阶段是相互独立的;因此,您还需要在您的
build: commands:中使用- export KUBECONFIG=$KUBECONFIG:~/.kube/config,或者做正确的事情并将其设置为整个管道的变量,如果 CodeBuild 足够聪明的话 -
@mdaniel 我已经试过了,结果是没有。
标签: kubernetes kubectl aws-codebuild amazon-eks