Github Action: Creating namespace using kubectl in order to deploy the build

8/2/2021

I am creating a GitHub workflow action, to deploy the build into an integration cluster and for that first, I wanted to create a namespace using kubectl, but I am getting an error: error: You must be logged in to the server (Unauthorized)

Here is my action.yaml snippet

        uses: cancue/eks-action@v0.0.2
        env:
          aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws_region: $AWS_REGION
          cluster_name: $EKS_CLUSTER_NAME
          kubeconfig: ${{ secrets.INTEGRATION_CLUSTER_SECRETS }}
        with:
          args: |
             kubectl create ns namespace:pr#${{ github.sha }}

I am new to writing action workflows. Thanks in advance.

-- Nitika Gahlawat
amazon-eks
continuous-deployment
github-actions
kubernetes
workflow

1 Answer

8/3/2021

you can try out the

- name: verify deployment
      uses: kodermax/kubectl-aws-eks@master
      env:
        KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
      with:
        args: create ns <namespace-name>

however your config looks good but makesure you have added the proper data for kubeconfig.

Also, check access_key and secret_key you are using have the access to EKS cluster.

Example : https://github.com/marketplace/actions/kubectl-aws-eks

Quick fix :

Once your access & secret set in environment use the command to featch the config from AWS, and you can remove adding the config file in Gitaction seceret.

aws eks update-kubeconfig --region ap-south-1 --name <Cluster name>

Secrets

KUBE_CONFIG_DATA – required: A base64-encoded kubeconfig file with credentials for Kubernetes to access the cluster. You can get it by running the following command:

cat $HOME/.kube/config | base64
-- Harsh Manvar
Source: StackOverflow