Install Karpenter and configure nodes
Install the Karpenter Provider in a Kubernetes Engine cluster and configure automatic worker node provisioning and reclamation.
Before you begin
Prepare the following items.
- A running Kubernetes Engine cluster in
kr-central-2and at least one managed Virtual Machine node to run the Karpenter controller - A kubeconfig with cluster administrator permissions, kubectl, and Helm 3.8.0 or later
- Project ID, cluster name, worker subnet ID, and Kubernetes Engine worker security group ID
- An IAM access key dedicated to Karpenter
Step 1. Create Secrets
IAM access key permissions follow the project roles assigned to the issuing account. Assign roles that allow the following operations to the account Karpenter will use, and then issue an IAM access key.
| Service | Required permissions |
|---|---|
| IAM | Issue tokens |
| Virtual Machine instances | Create, view, edit descriptions, and delete |
| Instance types | View |
| Key pairs | View (when using spec.keyName) |
| VPC | View subnets |
| Network | View security groups |
| Kubernetes Engine | View worker images, supported Kubernetes versions, clusters, and node pools |
Permission to edit instance descriptions is required to record ownership information. Because instance deletion permission is also required, restrict access to view Secrets.
Create a dedicated Karpenter namespace and a Secret for API calls.
kubectl create namespace karpenter-kakaocloud --dry-run=client -o yaml \
| kubectl apply -f -
export APP_CRED_ID='<IAM_ACCESS_KEY_ID>'
export APP_CRED_SECRET='<IAM_ACCESS_KEY_SECRET>'
kubectl -n karpenter-kakaocloud create secret generic kakaocloud-credentials \
--from-literal=applicationCredentialId="$APP_CRED_ID" \
--from-literal=applicationCredentialSecret="$APP_CRED_SECRET" \
--from-literal=region=kr-central-2
unset APP_CRED_ID APP_CRED_SECRET
Verify that the required keys have been created in the Secret. The output must include applicationCredentialId, applicationCredentialSecret, and region.
kubectl -n karpenter-kakaocloud get secret kakaocloud-credentials \
-o go-template='{{range $key, $value := .data}}{{$key}}{{"\n"}}{{end}}'
The signing key is used to verify ownership of and delete Karpenter instances. Generate it only once per cluster and back it up. Regenerating it during a Helm upgrade or GitOps synchronization may prevent reclamation of existing instances.
Generate a 32-byte signing key to verify instance ownership and store it in a Secret.
KEY=$(head -c 32 /dev/urandom | base64)
printf '{"activeKeyID":"k1","keys":[{"id":"k1","key":"%s"}]}\n' "$KEY" > keyring.json
kubectl -n karpenter-kakaocloud create secret generic karpenter-sigkey \
--from-file=keyring.json=./keyring.json
unset KEY
Back up keyring.json in a secure location, and then delete it from the working directory. activeKeyID can contain up to 7 characters, and the data key name must be keyring.json.
Step 2. Install Karpenter
Before installation, check the network paths for the controller and the nodes to be created. Private subnets must be able to access required external services through NAT. Karpenter nodes do not support bootstrapping through an HTTP proxy.
Check network destinations
The subnet for new nodes requires the following network paths.
- Kubernetes API server and KakaoCloud OpenAPI
- Container image registries and time synchronization servers
- Metadata service
169.254.169.254 - Cluster internal domain name resolution and CNI communication
The Karpenter controller must be able to access the following KakaoCloud OpenAPI hosts over HTTPS (443).
| Service | Host |
|---|---|
| IAM | iam.kakaocloud.com |
| Virtual Machine | bcs.kr-central-2.kakaocloud.com |
| VPC | vpc.kr-central-2.kakaocloud.com |
| Network | network.kr-central-2.kakaocloud.com |
| Image | image.kr-central-2.kakaocloud.com |
| Volume | volume.kr-central-2.kakaocloud.com |
| Kubernetes Engine | kubernetes-engine.kr-central-2.kakaocloud.com |
Access to ke-container-registry.kr-central-2.kcr.dev is also required to pull the controller image and Helm chart. Apply the same cluster and CNI communication rules to security groups as for existing Kubernetes Engine worker nodes.
Install the Karpenter Provider using the Helm OCI chart.
export KARPENTER_CHART_VERSION='0.1.0'
helm upgrade --install karpenter-provider-kakaocloud \
oci://ke-container-registry.kr-central-2.kcr.dev/ke-helm-public/karpenter-provider-kakaocloud \
--version "$KARPENTER_CHART_VERSION" \
--namespace karpenter-kakaocloud \
--create-namespace \
--set clusterName='<KE_CLUSTER_NAME>' \
--set projectID='<PROJECT_ID>' \
--set credentials.secretName=kakaocloud-credentials \
--set sigKey.secretName=karpenter-sigkey \
--wait \
--timeout 10m
Use the controller image included in the chart. Do not separately specify controller.image.*, region, or clusterUID values.
The Helm chart's default affinity prevents the controller from being scheduled on Karpenter nodes. If you change affinity in a custom values file, retain the condition that excludes nodes with the karpenter.sh/nodepool label.
Check the controller status.
kubectl -n karpenter-kakaocloud get deployment karpenter-provider-kakaocloud
kubectl -n karpenter-kakaocloud get pods
Verify that the Deployment has READY set to 1/1 and the Pod is Running.
Step 3. Create KCNodeClass
Configure the network, root volume, and Kubernetes version of nodes to be created by Karpenter in KCNodeClass.
Check the Kubernetes version in Cluster details. In KCNodeClass, specify a minor version equal to or one version below the control plane, without the patch number. For example, if the cluster version is 1.35, specify 1.35 or 1.34 as offered by Kubernetes Engine.
Also check existing worker node versions. If the following command returns v1.35.2, the minor version is 1.35.
kubectl get nodes -o custom-columns='NODE:.metadata.name,VERSION:.status.nodeInfo.kubeletVersion'
Create a kcnodeclass.yaml file.
apiVersion: karpenter.kakaocloud.com/v1alpha1
kind: KCNodeClass
metadata:
name: karpenter-default
spec:
subnetSelectorTerms:
- id: <SUBNET_ID>
securityGroupSelectorTerms:
- id: <WORKER_SECURITY_GROUP_ID>
rootVolume:
sizeGiB: 50
deleteOnTermination: true
bootstrap:
mode: Kubeadm
kubernetesVersion: "<KUBERNETES_MAJOR.MINOR>"
Find the ID for subnetSelectorTerms in the subnet list. Include the worker security group used by existing node pools in securityGroupSelectorTerms.
Add entries for any additional security groups you need. If you use an SSH key pair, specify its name in spec.keyName.
Set rootVolume.sizeGiB to at least 30 GiB. If you change deleteOnTermination to false, the root volume remains after instance deletion and continues to incur charges.
If you specify an unsupported version, KCNodeClass becomes Ready=False and cannot create nodes. For existing configurations using a deprecated version, see Manage deprecated Kubernetes versions.
Create KCNodeClass and check its readiness.
kubectl apply -f kcnodeclass.yaml
kubectl get kcnodeclass karpenter-default \
-o jsonpath='{range .status.conditions[*]}{.type}{"\t"}{.status}{"\n"}{end}'
Verify that the KubernetesVersionReady, ImagesReady, SubnetsReady, SecurityGroupsReady, KeyPairReady, and Ready conditions are all True.
Step 4. Create NodePool
Configure node provisioning requirements, resource limits, and reclamation policies in NodePool.
Check the cluster CNI.
kubectl get daemonset -A | grep -E 'cilium|calico-node'
- A
ciliumDaemonSet indicates Cilium. - A
calico-nodeDaemonSet indicates Calico.
Create a nodepool.yaml file.
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: karpenter-default
spec:
template:
metadata:
labels:
workload-type: karpenter
kakaoi.io/kke-nodepool: karpenter-default
spec:
requirements:
- key: kubernetes.io/os
operator: In
values: ["linux"]
- key: kubernetes.io/arch
operator: In
values: ["amd64"]
- key: karpenter.sh/capacity-type
operator: In
values: ["on-demand"]
nodeClassRef:
group: karpenter.kakaocloud.com
kind: KCNodeClass
name: karpenter-default
expireAfter: 720h
disruption:
consolidationPolicy: WhenEmptyOrUnderutilized
consolidateAfter: 10m
limits:
cpu: "40"
memory: 160Gi
For clusters using Cilium, add the following startup taint under spec.template.spec. Do not add it for clusters using Calico.
startupTaints:
- key: node.cilium.io/agent-not-ready
value: "true"
effect: NoExecute
Create the NodePool and check its status.
kubectl apply -f nodepool.yaml
kubectl get nodepool karpenter-default
Verify that READY is True. To restrict instance types or availability zones, see Configure node provisioning and reclamation policies.
The kakaoi.io/kke-nodepool label identifies Karpenter nodes in the KakaoCloud Console. Manage node provisioning and reclamation through Karpenter resources rather than the console's node pool features.
NodePool names must be no longer than 38 characters. Virtual Machine names generated by Karpenter include both the cluster identifier and NodeClaim name. Exceeding the limit may cause instance creation to fail.
Separate workloads so managed node pool autoscaling and Karpenter do not target the same workload. For workloads to run on Karpenter, use nodeSelector to select the workload-type: karpenter label as in the example below.
For managed node pool labels and taints, see Create node pool.
Step 5. Verify automatic node provisioning
Deploy a test workload to verify that Karpenter creates a NodeClaim and worker node. A NodeClaim represents a node created by Karpenter.
apiVersion: apps/v1
kind: Deployment
metadata:
name: karpenter-demo
spec:
replicas: 3
selector:
matchLabels:
app: karpenter-demo
template:
metadata:
labels:
app: karpenter-demo
spec:
nodeSelector:
workload-type: karpenter
containers:
- name: pause
image: registry.k8s.io/pause:3.9
resources:
requests:
cpu: "1"
memory: 2Gi
kubectl apply -f karpenter-demo.yaml
kubectl get nodeclaims
kubectl get nodes -l karpenter.sh/nodepool=karpenter-default
kubectl get pods -l app=karpenter-demo -o wide
Verify that a NodeClaim is created, the new node is Ready, and the test Pods are Running. Also check instances created by Karpenter in Virtual Machine > Instances in the KakaoCloud Console.
Delete the test workload after verification.
kubectl delete -f karpenter-demo.yaml
After consolidateAfter elapses, verify that empty nodes and NodeClaims are reclaimed. Also verify instance deletion in the KakaoCloud Console.
To remove Karpenter, see Manage and uninstall Karpenter.