AWS - Private EKS clusters#
Introduction#
This guide adapts the AWS getting started guide to a private cluster:
- the nodes have no route to the internet, and reach AWS through VPC endpoints;
- the Kubernetes API endpoint is private, so only machines in the VPC or connected to it reach it;
- every load balancer is internal, so only clients in the VPC or connected to it reach Hopsworks.
It lists only what changes from the getting started guide, which you follow for everything else. It assumes a VPC with private subnets in at least two availability zones.
Network#
Create these VPC endpoints in the VPC, with private DNS names enabled on the interface endpoints, before you create the cluster. The nodes and the AWS controllers call these services, and without an endpoint the call goes nowhere.
| Endpoint | Type | Needed for |
|---|---|---|
com.amazonaws.REGION.ec2 | Interface | Nodes joining, the VPC CNI, the EBS CSI driver, the AWS Load Balancer Controller |
com.amazonaws.REGION.ecr.api, com.amazonaws.REGION.ecr.dkr | Interface | Image pulls from Amazon ECR |
com.amazonaws.REGION.s3 | Gateway | Image layers from Amazon ECR, the Hopsworks bucket, Velero backups |
com.amazonaws.REGION.sts | Interface | IAM roles for service accounts, such as the EBS CSI driver's |
com.amazonaws.REGION.elasticloadbalancing | Interface | The AWS Load Balancer Controller |
com.amazonaws.REGION.eks | Interface | Calls to the EKS API from the VPC, such as by eksctl |
com.amazonaws.REGION.eks-auth | Interface | EKS Pod Identity, when you use it |
com.amazonaws.REGION.oidc-eks | Interface | Setting up IAM roles for service accounts from inside the VPC |
com.amazonaws.REGION.ssm | Interface | AMI lookups through SSM parameters, such as Karpenter's |
com.amazonaws.REGION.ssmmessages | Interface | Session Manager, when you reach the cluster through it (Cluster and access) |
com.amazonaws.REGION.ec2messages | Interface | Session Manager with older SSM Agent versions, in regions that offer it |
com.amazonaws.REGION.sqs | Interface | Karpenter's interruption queue, when you use Karpenter |
com.amazonaws.REGION.logs | Interface | Node or pod logs sent to Amazon CloudWatch Logs |
- Associate the S3 gateway endpoint with the route tables of the private subnets. If you give the endpoint a policy of your own, it must allow the Hopsworks bucket and
arn:aws:s3:::prod-REGION-starport-layer-bucket/*, where Amazon ECR keeps image layers, or nodes authenticate to Amazon ECR and then fail to download the layers. - The VPC needs DNS support and DNS hostnames enabled, so that the endpoints' private names resolve.
- The security group of the interface endpoints admits the nodes and pods on port 443.
- The AWS documentation lists the endpoints for other AWS services in Deploy private clusters with limited internet access.
Cluster and access#
With a private API endpoint, kubectl, helm and eksctl work only from a machine that reaches the endpoint: one in the VPC, or one connected to it over a VPN, VPC peering or AWS Direct Connect. That machine also needs to resolve the endpoint's name, the cluster's security group must admit it on port 443, and its IAM principal needs an access entry on the cluster. eksctl and the IAM steps of the getting started guide call AWS APIs that the endpoints above do not cover, such as AWS CloudFormation and IAM, so run them from a machine that reaches those APIs. The same machine installs Hopsworks, so stage on it the charts that the getting started guide downloads (the Hopsworks chart and the AWS Load Balancer Controller's chart), with helm pull on a machine with internet access, when it has none.
Without a network path into the VPC, AWS Systems Manager Session Manager forwards a local port to the endpoint through an instance in a private subnet. The instance needs an instance profile with AmazonSSMManagedInstanceCore, and the VPC the ssm and ssmmessages endpoints, and ec2messages where the region offers it. ENDPOINT_HOST is the cluster's endpoint without https://, from aws eks describe-cluster --name CLUSTER_NAME --query cluster.endpoint. Start the forwarding in one terminal and leave it running:
aws ssm start-session --target INSTANCE_ID \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters "host=ENDPOINT_HOST,portNumber=443,localPortNumber=8443"
In a second terminal, point a copy of the kubeconfig at the local port and keep the endpoint's name for TLS:
cp ~/.kube/config kubeconfig-tunnel
export KUBECONFIG=$PWD/kubeconfig-tunnel
kubectl config set-cluster "$(kubectl config view --minify -o jsonpath='{.clusters[0].name}')" \
--server=https://localhost:8443 --tls-server-name=ENDPOINT_HOST
kubectl get nodes
In the getting started guide's eksctl.yaml, add the private cluster settings and your private subnets, and set privateNetworking: true on every node group:
privateCluster:
enabled: true
skipEndpointCreation: true
vpc:
subnets:
private:
REGION_ZONE_A:
id: SUBNET_ID_A
REGION_ZONE_B:
id: SUBNET_ID_B
managedNodeGroups:
- name: ng-1
privateNetworking: true
# the rest of the node group as in the getting started guide
skipEndpointCreation: trueuses the endpoints you created, because eksctl's own set lacks some that Hopsworks needs, such aselasticloadbalancing.- eksctl creates the cluster with both public and private API access and switches public access off only once creation is complete, as described in eksctl fully private clusters. If the API endpoint must never be public, create the cluster with a tool that sets private access only from the start, and apply the node group settings of the getting started guide.
- If you use custom security groups for the nodes, the control plane must reach the nodes on the ports the pods listen on, because admission webhooks run in pods.
Images#
The nodes pull every image from Amazon ECR, through the endpoints. Follow Pull-through cache on Amazon ECR for the Hopsworks images, with one change: let the cache rule mirror the whole of Amazon ECR Public, so that it also serves the images of the AWS Load Balancer Controller and Karpenter, which AWS publishes there:
aws ecr create-pull-through-cache-rule --ecr-repository-prefix ecr-public --upstream-registry ecr-public --upstream-registry-url public.ecr.aws --region REGION --profile PROFILE
- With this rule,
REGISTRYfor the Hopsworks images isECR_AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/ecr-public/c8w3j7u1, and the node role needsecr:CreateRepositoryandecr:BatchImportUpstreamImageonarn:aws:ecr:REGION:ECR_AWS_ACCOUNT_ID:repository/ecr-public/*. - The AWS Load Balancer Controller's image is
ECR_AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/ecr-public/eks/aws-load-balancer-controller, which its chart takes asimage.repository. - A VPC without an internet route cannot fetch an image through the cache on its first pull, as AWS documents, so pull every image once through the cache from a machine with internet access before you install the controllers and Hopsworks: the images of the controllers, every image in Images to mirror, and Velero's when you enable backups. Do it again for the new images of every upgrade.
- The repository for project environment images,
NAMESPACE/hopsworks-basein the getting started guide, stays a repository of its own: Hopsworks pushes to it, while the node role only reads and imports through the cache. - The EKS add-ons, such as the VPC CNI, CoreDNS and the EBS CSI driver, come from AWS's own registry in your region, through the same endpoints.
Node pools#
-
Hopsworks pods use the node role to reach Amazon S3 and Amazon ECR, through the instance metadata service. Their requests pass one extra network hop, so the nodes need IMDSv2 with a hop limit of at least 2. Check it on the nodes of each node group:
-
Managed node groups, as in the getting started guide, are the simplest layout. If you add Karpenter, as described in AWS - Autoscaling with Karpenter, use it for the compute pool only, and keep CoreDNS, the AWS Load Balancer Controller and Karpenter itself on managed node groups, because they must run before Karpenter can create a node. On a private cluster, Karpenter also needs
settings.isolatedVPC: true, because the AWS pricing API it calls is not among the endpoints above, and its nodes need the same hop limit and the node policy of the getting started guide. - Keep the RonDB data nodes on managed node groups with nodes in every availability zone that holds one of their volumes, because an EBS volume cannot move to another zone.
Load balancers, DNS and certificates#
Install the AWS Load Balancer Controller from the staged chart, with its image from your registry and its Shield and WAF integrations off, because those services have no VPC endpoint:
helm install aws-load-balancer-controller aws-load-balancer-controller-VERSION.tgz -n kube-system --set clusterName=CLUSTER_NAME --set region=REGION --set vpcId=VPC_ID --set image.repository=ECR_AWS_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/ecr-public/eks/aws-load-balancer-controller --set enableShield=false --set enableWaf=false --set enableWafv2=false
Then make every load balancer of the getting started guide's values internal, in a values file of its own passed after values.aws.yaml:
global:
_hopsworks:
externalLoadBalancers:
annotations:
service.beta.kubernetes.io/aws-load-balancer-scheme: internal
hopsworks:
ingress:
annotations:
alb.ingress.kubernetes.io/scheme: internal
rondb:
rondb:
meta:
mysqld:
externalLoadBalancer:
annotations:
service.beta.kubernetes.io/aws-load-balancer-scheme: internal
rdrs:
externalLoadBalancer:
annotations:
service.beta.kubernetes.io/aws-load-balancer-scheme: internal
- The
globalannotation also reaches Kafka's load balancers. The model serving gateway's load balancer takes no annotations from the values, so the controller creates it with its default scheme,internal. - The controller places internal load balancers in the subnets tagged
kubernetes.io/role/internal-elbwith value1, as described in Subnet auto-discovery. Tag the private subnets, or name them in thealb.ingress.kubernetes.io/subnetsandservice.beta.kubernetes.io/aws-load-balancer-subnetsannotations. - To put the services behind one internal load balancer that you create yourself, follow Shared load balancers on AWS instead of the
globalandrondbpart above. The UI and REST API stay behind the Ingress in both cases, so keep itsinternalscheme. - Point
HOST_DOMAINat the internal application load balancer in a private hosted zone of Amazon Route 53, or in your own DNS. - An ACM certificate requested with DNS validation needs its validation record in public DNS, which a private-only domain does not have. For such a domain, use a certificate from a private certificate authority, or import one into ACM in the cluster's region, and make the clients trust its issuer.
CoreDNS and Consul#
Hopsworks services find each other through Consul, and by default the chart adds a block that forwards Consul names to Consul into the coredns ConfigMap. On EKS with the CoreDNS add-on, the add-on owns that configuration: an update of the add-on that overwrites its configuration removes the block, and Consul names stop resolving until the block is added again. An upgrade with the chart's CoreDNS configuration hook tries to add it, but goes on when it cannot, so check the Corefile after it. To keep the block through add-on updates, give Consul's DNS Service a fixed address and put the block in the add-on's own configuration, before you install Hopsworks:
-
Choose an unused address in the cluster's Service address range, which
aws eks describe-cluster --name CLUSTER_NAME --query cluster.kubernetesNetworkConfig.serviceIpv4Cidrprints, and check that no Service has it:kubectl get services -A -o jsonpath='{.items[*].spec.clusterIP}' | tr ' ' '\n' | grep -x CONSUL_DNS_ADDRESSOn a cluster where Hopsworks already runs, use the address of its Consul DNS Service instead, because a Service's address cannot change:
-
Read the add-on's current
Corefilewithkubectl get configmap coredns -n kube-system -o jsonpath='{.data.Corefile}', and writecoredns.yamlwith thatCorefile, unchanged, in place of the comment line, followed by the Consul block:An update replaces the add-on's whole configuration, so also copy into
coredns.yamlany other settings the add-on has, whichaws eks describe-addon --cluster-name CLUSTER_NAME --addon-name coredns --query addon.configurationValuesprints. 3. Apply it to the add-on, and wait until the update is done:aws eks update-addon --cluster-name CLUSTER_NAME --addon-name coredns --configuration-values file://coredns.yaml --resolve-conflicts OVERWRITE --region REGION --profile PROFILE aws eks wait addon-active --cluster-name CLUSTER_NAME --addon-name coredns --region REGION --profile PROFILEOn a cluster where Hopsworks already runs, the chart wrote the
Corefileitself, and an update that does not overwrite it can fail on that conflict. Overwriting is safe here, becausecoredns.yamlholds the wholeCorefile. -
Add to the values file of the private cluster:
With autoConfigureCoreDNS: false the chart leaves CoreDNS alone, so from then on the add-on's configuration is the only place the block lives: keep it in every later update of the add-on. On a cluster where Hopsworks already runs with the default setting, the Corefile you read in step 2 already holds the chart's Consul block: leave that block out, because two blocks for the same zone stop CoreDNS from loading its configuration.
Downloads at run time#
Hopsworks itself runs from the images in your registry, but some features download at run time:
-
Project Python environments install packages from a Python package index, by default PyPI. Point them at a mirror reachable from the VPC, which environment builds then use instead of any other index:
The library search of the Hopsworks UI reads the index from the
pypi_simple_endpointandpypi_rest_endpointvariables of the cluster configuration, which point at PyPI by default. - Custom commands in an environment, such asapt-get, and any artifact URL you configure need their sources reachable from the VPC, or the files staged in a reachable location.
Check#
Besides the checks of the getting started guide:
-
The API endpoint is private only:
aws eks describe-cluster --name CLUSTER_NAME --query 'cluster.resourcesVpcConfig.[endpointPrivateAccess,endpointPublicAccess]' --region REGION --profile PROFILEIt prints
trueandfalse. - No route of the node subnets leads to an internet or NAT gateway. The command prints the route tables of the node subnets, each with its subnets and routes, and no route may have anigw-ornat-target:aws ec2 describe-route-tables --filters Name=association.subnet-id,Values=SUBNET_ID_A,SUBNET_ID_B --query 'RouteTables[].[Associations[].SubnetId,Routes[].[DestinationCidrBlock,GatewayId,NatGatewayId]]' --region REGION --profile PROFILEA node subnet missing from the output has no table of its own and uses the VPC's main table: check that one too, with the filter
Name=vpc-id,Values=VPC_ID Name=association.main,Values=true. -
Every load balancer of the release has the scheme
internal: -
From a machine in the VPC,
https://HOST_DOMAINopens with a verified certificate. -
The cluster DNS configuration holds the Consul block from the add-on's configuration: