Kubectl and several AWS accounts

Viewed 316

I'm using on AWS the service EKS, and I use kubectl in order to manage all the kubernetes infrastructure. I've several aws profiles, and I need to switch among these ones when needed.

What is the best way to switch from an aws profile to another one, in order to call the same kubectl command but in different aws accounts?

Thanks

1 Answers

In your ~/.kube/config you can set which profile to use.

Example:

users:
- name: arn:aws:eks:us-east-1:########:cluster/production
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-east-1
      env:
      - name: AWS_PROFILE
        value: <my-profile>
      command: aws

If you need to change it you could edit the file.

Another option, if you want to be able to change profiles easier is to create separate config files for each profile. Then when you run a command, you can set the KUBECONFIG value: KUBECONFIG=~/.kube/config-alternate kubectl .... That could be aliased for easier use as well. If there is an easier way, I don't know it.

Related