<p>I have deployed an EKS cluster with a private endpoint (with the help of vpc endpoints). There is no public endpoint and there is no internet gateway.</p>
<p>I need to understand how to access the Kubernetes API from an EC2 instance launched in one of the private subnets in the same VPC. I am using Session Manager with vpc endpoint to run commands on the EC2 instance.</p>
<p>Any advice on how to install and configure kubectl to manage the cluster in this case?</p>

<p>There are several ways to achieve this:</p>
<ul>
<li>If you have an on-premise sever in your on-premise network that is connected to the underlying VPC of the EKS cluster (You can connect them via AWS VPN or Direct Connect), you can configure your <code>kubectl</code> to connect via this private connectivity. <strong>PS</strong>: You have to be careful of subnet segment selection to avoid conflicting CIDRs and ease integration of the networks</li>
<li>You can setup a bastion on the public subnet and use it as a jumpbox for connecting to another EC2 inside the private subnet. In that private EC2, you can install <code>kubectl</code> and integrate with the EKS API server, the connectivity could then be setup thanks to the private endpoints with EKS.</li>
<li>(UPDATE): You can also use AWS SSM to connect to a private EC2 server that contains a <code>kubectl</code> that can manage the EKS cluster (Same suggestion with gohmc).</li>
<li>If you have a Cloud9 server that can connect to the underlying VPC of the EKS server, you can use that as a base of your <code>kubectl</code> and manage it from there.</li>
<li>You can introduce an automation VPC that can connect to the underlying VPC of the EKS cluster via VPC Peering or Transient Gateways, you can use that VPC to host your CI/CD servers (Jenkins or TeamCity) plus your command center EC2 that contains a <code>kubectl</code> for debugging purpose, this can also be a great place to host your other kubernetes tooling.</li>
</ul>
<p>If you don't want to open internet traffic in your EKS VPC, you can follow this steps:</p>
<ul>
<li>Provision another VPC or use the default VPC of the account</li>
<li>Create an EC2 with internet access</li>
<li>Install all OS updates on this EC2</li>
<li>Install kubectl on this EC2</li>
<li>Download other software you'll need in this EC2</li>
<li>Create an AMI out of this EC2</li>
<li>Spin a new EC2 using the AMI created on the previous step inside the EKS VPC</li>
<li>SSM to that EC2</li>
</ul>
<p>Now, if your EKS VPC contains private endpoints that can connect to EKS, you can use <code>kubectl</code> to connect to that API server via the VPC's private endpoint</p>
<p>To be honest, I'm excited to see a command portal inside the AWS console that would allow us to do this easily instead of having to perform hardcore network setups.</p>
