I want to deploy Kubernetes service/deployment yaml files from CodePipeline which is in account A and the EKS cluster is in account B.
I tried the following approach.
On Account A:
- Created assume role policy and attached it to the codebuild role which is associated with the codepipeline.
- Passed the role name from account A in assume role policy which has eks full access.
On Account B:
- Created a role with access to EKS cluster.
- Added the above role arn to the Kubernetes config with system:masters permission.
Buildspec file from Account A:
version: 0.2
run-as: root
phases:
install:
commands:
- echo Installing app dependencies...
- curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/darwin/amd64/kubectl
- chmod +x ./kubectl
- mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
- echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
- source ~/.bashrc
- echo 'Check kubectl version'
- kubectl version --short --client
#- chmod +x eks_cicd/prereqs.sh
#- sh eks_cicd/prereqs.sh
build:
commands:
- echo Logging in to Amazon EKS...
- aws sts get-caller-identity
- aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $AWS_CLUSTER_NAME --role-arn $ASSUMEROLE_ARN
- echo check config
- kubectl config view --minify
- echo check kubectl access
- kubectl get svc
post_build:
commands:
- kubectl apply -f ingress.yml
#- kubectl rollout restart -f eks_cicd/deployment.yaml
But I'm getting this error:
An error occurred (ResourceNotFoundException) when calling the DescribeCluster operation: No cluster found for name: DevCluster.