I am new to Kubernetes and trying to create a AWS CodePipeline to deploy service to EKS stack.
I am following this tutorial I have followed all the steps including creating a role and adding permissions, so that CodeBuild will be able to talk with EKS.
The issue I am facing right now is when CodePipeline runs, it is failing for below command in the CodeBuild phase.
kubectl apply -f hello-k8s.yml
and giving this error
[Container] 2019/12/04 07:41:43 Running command kubectl apply -f hello-k8s.yml
unable to recognize "hello-k8s.yml": Unauthorized
unable to recognize "hello-k8s.yml": Unauthorized
I am not very much sure whether its a credentials issue, because I have used all the steps to add user/role as per tutorial.
Can anyone please help me on this?
Deploying Yaml manifests to Kubernetes from CodeBuild requires these steps:
The high-level process includes the following steps:
Create an IAM Service role for CodeBuild
Map the CodeBuild Service role in EKS using “aws-auth” ConfigMap
Create source files in Code repository
Create and Start a CodeBuild Project
Confirm the required objects are created in EKS cluster
Create an IAM Service role for CodeBuild (Don't use existing service role as it includes a '/path/')
Run the following commands to Create a CodeBuild Service Role and attach the required policies:
Map the CodeBuild Service role in EKS using “aws-auth” ConfigMap
Edit the ‘aws-auth’ ConfigMap and add the Role Mapping for the CodeBuild service role:
Create source files in Code repository
Create a repository in Github/CodeCommit with sample files as follows:
A sample repository is located here: https://github.com/shariqmus/codebuild-to-eks
Notes:
The buildspec.yml file installs kubectl, aws-iam-authenticator and configure kubectl in CodeBuild environment
Update the buildspec.yml file with the correct region and cluster_name on Line 16
Add the deployment YAML files in the “deployment” directory
Create and Start a Build Project
Open the CodeBuild console
Click ‘Create Build Project’ button
Name the Project
Use a CodeCommit repository where you have added the attached files : “buildspec.yml” and “pod.yaml”
Use Managed Image > Ubuntu > Standard 1.0
In the Role Name, select “CodeBuildKubectlRole”
Click ‘Create Build Project’ button
Create ‘Start Build’ button to start a Build
Confirm the required objects are created in EKS cluster
You can confirm this with a simple command, e.g.