<p>Currently, there are two eks cluster a prod and dev. I am trying to access the dev cluster which exists in a different aws account and it gives me an error "You must be logged in to the server"</p>

<p>When I try to get the kubectl version I am getting an error. Please point my mistake. This happens only with the dev cluster. Please also let me know the steps to correct if I am wrong anywhere.</p>

<pre><code>AWS_PROFILE=eks_admin_dev kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-07-26T20:40:11Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
error: You must be logged in to the server (the server has asked for the client to provide credentials)

AWS_PROFILE=eks_admin_dev kubectl get pods
error: You must be logged in to the server (Unauthorized)
</code></pre>

<p>I have created access key and secret access key for my dev user( which are admin credentials). I created two profiles dev and eks_admin_dev. 
I understand that the source_profile part is telling it to use the dev profile to do an sts:AssumeRole for the eks-admin role.</p>

<pre><code>$ aws --version
aws-cli/1.16.45 Python/2.7.12 Linux/4.4.0-1066-aws botocore/1.12.35

$ kubectl config current-context
dev

$ cat ~/.aws/config
[default]   ---&gt; prod account 
region = us-east-1
[profile eks_admin_dev] ---&gt; dev account
role_arn = arn:aws:iam::xxxxxxxx:role/eks-admin
source_profile = dev
region = us-east
[profile dev]  ---&gt; dev account
region = us-east-1
</code></pre>

<p>my credentials:</p>

<pre><code>$ cat ~/.aws/credentials
[old]
aws_secret_access_key = xxxxxxxxxxxxxx
aws_access_key_id = xxxxxxxxx
[default]
aws_access_key_id = xxxxxx
aws_secret_access_key = xxx
[dev]
aws_secret_access_key = xxx
aws_access_key_id = xxx
[eks_admin_dev]
aws_access_key_id = xx
aws_secret_access_key = xx
</code></pre>

<p><code>cat ~/.kube/kubeconfig</code>, I tried specifying the role here, same error.</p>

<pre><code>users:
- name: aws
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - token
      - -i
      - dev-0
      command: aws-iam-authenticator
      env:
      - name: AWS_PROFILE
        value: eks_admin_dev
</code></pre>

<p>This works for me using both the <code>AWS_PROFILE</code> env on the command line and also setting the env in the <code>~/.kube/config</code> file.</p>

<p>The only thing that I can think may be happening is that you have the AWS credentials predefined for your prod account in the bash env already (Those take precedence over what's in <code>~/.aws/credentials</code>. You can check with this:</p>

<pre><code>$ env | grep AWS
AWS_SECRET_ACCESS_KEY=xxxxxxxx
AWS_ACCESS_KEY_ID=xxxxxxxxx
</code></pre>

<p>If that's the case you can unset them or remove them from whatever init file you may be sourcing on your shell.</p>

<pre><code>$ unset AWS_SECRET_ACCESS_KEY
$ unset AWS_ACCESS_KEY_ID
</code></pre>
