Skip to content

Instantly share code, notes, and snippets.

@cc4i
Last active October 12, 2019 07:26
Show Gist options
  • Save cc4i/b726216fa725fae64858eadf3cf7b08e to your computer and use it in GitHub Desktop.
Save cc4i/b726216fa725fae64858eadf3cf7b08e to your computer and use it in GitHub Desktop.
Run following code with CDK 1.12.0 & failed to call API
import cdk = require('@aws-cdk/core');
import ec2 = require( '@aws-cdk/aws-ec2');
import eks = require('@aws-cdk/aws-eks');
import iam = require('@aws-cdk/aws-iam');
export class EksStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'eksClusterVPC');
const cluster = new eks.Cluster(this, "eksCluster", {
vpc: vpc,
defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE),
defaultCapacity: 1
});
}
}
@cc4i
Copy link
Author

cc4i commented Oct 12, 2019

k get nodes

“error: You must be logged in to the server (Unauthorized)”

@cc4i
Copy link
Author

cc4i commented Oct 12, 2019

cdk --version
1.12.0 (build 923055e)

@cc4i
Copy link
Author

cc4i commented Oct 12, 2019

Fixed:

Find out role ARN,
update-kubeconfig with role ARN

or
Specify role,
const clusterAdmin = new iam.Role(this, 'AdminRole', {
assumedBy: new iam.AccountRootPrincipal()
});

@cc4i
Copy link
Author

cc4i commented Oct 12, 2019

const clusterAdmin = new iam.Role(this, 'AdminRole', {
assumedBy: new iam.AccountRootPrincipal()
});

const cluster = new eks.Cluster(this, "eksCluster", {
  vpc: vpc,
  defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE),
  defaultCapacity: 1,
  mastersRole: clusterAdmin
});

@pahud
Copy link

pahud commented Oct 12, 2019

所以你最後可以了嗎?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment