diff --git a/Makefile b/Makefile index 41da926f6..51247bdd0 100644 --- a/Makefile +++ b/Makefile @@ -319,6 +319,8 @@ dev-azure-creds: envsubst dev-vsphere-creds: envsubst @NAMESPACE=$(NAMESPACE) $(ENVSUBST) -no-unset -i config/dev/vsphere-credentials.yaml | $(KUBECTL) apply -f - +dev-eks-creds: dev-aws-creds + .PHONY: dev-apply ## Apply the development environment by deploying the kind cluster, local registry and the HMC helm chart. dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-release diff --git a/config/dev/eks-managedcluster.yaml b/config/dev/eks-managedcluster.yaml new file mode 100644 index 000000000..a6731163a --- /dev/null +++ b/config/dev/eks-managedcluster.yaml @@ -0,0 +1,11 @@ +apiVersion: hmc.mirantis.com/v1alpha1 +kind: ManagedCluster +metadata: + name: eks-dev + namespace: ${NAMESPACE} +spec: + config: + region: us-east-2 + workersNumber: 1 + template: aws-eks-0-0-1 + credential: "aws-cluster-identity-cred" diff --git a/docs/dev.md b/docs/dev.md index 19b40cec4..395fc2e6e 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -67,6 +67,14 @@ full explanation for each parameter visit [vSphere cluster parameters](cluster-parameters.md) and [vSphere machine parameters](machine-parameters.md). +### EKS Provider Setup + +To properly deploy dev cluster you need to have the following variable set: + +- `DEV_PROVIDER` - should be "eks" + +The rest of deployment procedure is the same as for other providers. + ## Deploy HMC Default provider which will be used to deploy cluster is AWS, if you want to use diff --git a/templates/cluster/aws-eks/.helmignore b/templates/cluster/aws-eks/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/templates/cluster/aws-eks/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/templates/cluster/aws-eks/Chart.yaml b/templates/cluster/aws-eks/Chart.yaml new file mode 100644 index 000000000..56513523a --- /dev/null +++ b/templates/cluster/aws-eks/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: aws-eks +description: | + An HMC template to deploy a cluster on EKS with bootstrapped control plane nodes. +type: application +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.0.1 +annotations: + hmc.mirantis.com/infrastructure-providers: aws + hmc.mirantis.com/controlplane-providers: eks + hmc.mirantis.com/bootstrap-providers: eks diff --git a/templates/cluster/aws-eks/templates/_helpers.tpl b/templates/cluster/aws-eks/templates/_helpers.tpl new file mode 100644 index 000000000..84d7d35f3 --- /dev/null +++ b/templates/cluster/aws-eks/templates/_helpers.tpl @@ -0,0 +1,19 @@ +{{- define "cluster.name" -}} + {{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "awsmachinetemplate.worker.name" -}} + {{- include "cluster.name" . }}-worker-mt +{{- end }} + +{{- define "machinedeployment.name" -}} + {{- include "cluster.name" . }}-md +{{- end }} + +{{- define "awsmanagedcontrolplane.name" -}} + {{- include "cluster.name" . }}-cp +{{- end }} + +{{- define "eksconfigtemplate.name" -}} + {{- include "cluster.name" . }}-machine-config +{{- end }} diff --git a/templates/cluster/aws-eks/templates/awsmachinetemplate-worker.yaml b/templates/cluster/aws-eks/templates/awsmachinetemplate-worker.yaml new file mode 100644 index 000000000..4cf5d7b13 --- /dev/null +++ b/templates/cluster/aws-eks/templates/awsmachinetemplate-worker.yaml @@ -0,0 +1,22 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSMachineTemplate +metadata: + name: {{ include "awsmachinetemplate.worker.name" . }} +spec: + template: + spec: + {{- if not (quote .Values.worker.amiID | empty) }} + ami: + id: {{ .Values.worker.amiID }} + {{- end }} + imageLookupFormat: {{ .Values.worker.imageLookup.format }} + imageLookupOrg: {{ .Values.worker.imageLookup.org }} + imageLookupBaseOS: {{ .Values.worker.imageLookup.baseOS }} + instanceType: {{ .Values.worker.instanceType }} + iamInstanceProfile: {{ .Values.worker.iamInstanceProfile }} + publicIP: {{ .Values.publicIP }} + rootVolume: + size: {{ .Values.worker.rootVolumeSize }} + {{- if not (quote .Values.sshKeyName | empty) }} + sshKeyName: {{ .Values.sshKeyName | quote }} + {{- end }} diff --git a/templates/cluster/aws-eks/templates/awsmanagedcluster.yaml b/templates/cluster/aws-eks/templates/awsmanagedcluster.yaml new file mode 100644 index 000000000..4eabcd383 --- /dev/null +++ b/templates/cluster/aws-eks/templates/awsmanagedcluster.yaml @@ -0,0 +1,7 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 +kind: AWSManagedCluster +metadata: + name: {{ include "cluster.name" . }} + annotations: + aws.cluster.x-k8s.io/external-resource-gc: "true" +spec: {} diff --git a/templates/cluster/aws-eks/templates/awsmanagedcontrolplane.yaml b/templates/cluster/aws-eks/templates/awsmanagedcontrolplane.yaml new file mode 100644 index 000000000..6807e5033 --- /dev/null +++ b/templates/cluster/aws-eks/templates/awsmanagedcontrolplane.yaml @@ -0,0 +1,14 @@ +apiVersion: controlplane.cluster.x-k8s.io/v1beta2 +kind: AWSManagedControlPlane +metadata: + name: {{ include "awsmanagedcontrolplane.name" . }} + namespace: hmc-system +spec: + region: {{ .Values.region }} + {{- if not (quote .Values.sshKeyName | empty) }} + sshKeyName: {{ .Values.sshKeyName | quote }} + {{- end }} + version: {{ .Values.kubernetes.version }} + identityRef: + kind: {{ .Values.clusterIdentity.kind }} + name: {{ .Values.clusterIdentity.name }} diff --git a/templates/cluster/aws-eks/templates/cluster.yaml b/templates/cluster/aws-eks/templates/cluster.yaml new file mode 100644 index 000000000..dca896de1 --- /dev/null +++ b/templates/cluster/aws-eks/templates/cluster.yaml @@ -0,0 +1,17 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: {{ include "cluster.name" . }} +spec: + {{- with .Values.clusterNetwork }} + clusterNetwork: + {{- toYaml . | nindent 4 }} + {{- end }} + controlPlaneRef: + apiVersion: controlplane.cluster.x-k8s.io/v1beta2 + kind: AWSManagedControlPlane + name: {{ include "awsmanagedcontrolplane.name" . }} + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSManagedCluster + name: {{ include "cluster.name" . }} diff --git a/templates/cluster/aws-eks/templates/eksconfigtemplate.yaml b/templates/cluster/aws-eks/templates/eksconfigtemplate.yaml new file mode 100644 index 000000000..cabd6204c --- /dev/null +++ b/templates/cluster/aws-eks/templates/eksconfigtemplate.yaml @@ -0,0 +1,6 @@ +apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 +kind: EKSConfigTemplate +metadata: + name: {{ include "eksconfigtemplate.name" . }} +spec: + template: {} diff --git a/templates/cluster/aws-eks/templates/machinedeployment.yaml b/templates/cluster/aws-eks/templates/machinedeployment.yaml new file mode 100644 index 000000000..d177494eb --- /dev/null +++ b/templates/cluster/aws-eks/templates/machinedeployment.yaml @@ -0,0 +1,26 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: MachineDeployment +metadata: + name: {{ include "machinedeployment.name" . }} +spec: + clusterName: {{ include "cluster.name" . }} + replicas: {{ .Values.workersNumber }} + selector: + matchLabels: + cluster.x-k8s.io/cluster-name: {{ include "cluster.name" . }} + template: + metadata: + labels: + cluster.x-k8s.io/cluster-name: {{ include "cluster.name" . }} + spec: + version: {{ .Values.kubernetes.version }} + clusterName: {{ include "cluster.name" . }} + bootstrap: + configRef: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta2 + kind: EKSConfigTemplate + name: {{ include "eksconfigtemplate.name" . }} + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta2 + kind: AWSMachineTemplate + name: {{ include "awsmachinetemplate.worker.name" . }} diff --git a/templates/cluster/aws-eks/values.schema.json b/templates/cluster/aws-eks/values.schema.json new file mode 100644 index 000000000..acabd799c --- /dev/null +++ b/templates/cluster/aws-eks/values.schema.json @@ -0,0 +1,146 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "description": "An HMC template to deploy a ManagedCluster on EKS.", + "type": "object", + "required": [ + "workersNumber", + "region", + "clusterIdentity" + ], + "properties": { + "workersNumber": { + "description": "The number of the worker machines", + "type": "number", + "minimum": 1 + }, + "clusterNetwork": { + "type": "object", + "properties": { + "pods": { + "type": "object", + "properties": { + "cidrBlocks": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + } + } + }, + "services": { + "type": "object", + "properties": { + "cidrBlocks": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + } + } + } + } + }, + "region": { + "description": "AWS region to deploy the cluster in", + "type": "string" + }, + "sshKeyName": { + "description": "The name of the key pair to securely connect to your instances. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)", + "type": [ + "string", + "null" + ] + }, + "publicIP": { + "description": "Specifies whether the instance should get a public IP", + "type": "boolean" + }, + "clusterIdentity": { + "type": "object", + "description": "AWS Cluster Identity object reference", + "required": [ + "name", + "kind" + ], + "properties": { + "name": { + "description": "AWS ClusterIdentity object name", + "type": "string" + }, + "kind": { + "description": "AWS ClusterIdentity object kind", + "type": "string" + } + } + }, + "worker": { + "description": "The configuration of the worker machines", + "type": "object", + "required": [ + "iamInstanceProfile", + "instanceType" + ], + "properties": { + "amiID": { + "description": "The ID of Amazon Machine Image", + "type": "string" + }, + "iamInstanceProfile": { + "description": "The name of an IAM instance profile to assign to the instance", + "type": "string" + }, + "instanceType": { + "description": "The type of instance to create", + "type": "string" + }, + "additionalSecurityGroupIDs": { + "description": "An array of references to security groups that should be applied to the instance", + "type": "array" + }, + "rootVolumeSize": { + "description": "The size of the root volume of the instance (GB)", + "type": "integer" + }, + "imageLookup": { + "description": "AMI lookup parameters", + "type": "object", + "required": [ + "format", + "org" + ], + "properties": { + "format": { + "description": "Format string which will be used for image lookup", + "type": "string" + }, + "org": { + "description": "AWS org ID which owns the AMI", + "type": "string" + }, + "baseOS": { + "description": "OS name which can be used in format string", + "type": "string" + } + } + } + } + }, + "kubernetes": { + "description": "Kubernetes parameters", + "type": "object", + "required": [ + "version" + ], + "properties": { + "version": { + "description": "Kubernetes version to use", + "type": "string" + } + } + } + } +} diff --git a/templates/cluster/aws-eks/values.yaml b/templates/cluster/aws-eks/values.yaml new file mode 100644 index 000000000..188b7818b --- /dev/null +++ b/templates/cluster/aws-eks/values.yaml @@ -0,0 +1,34 @@ +# Cluster parameters +workersNumber: 1 + +clusterNetwork: + pods: + cidrBlocks: + - "10.244.0.0/16" + services: + cidrBlocks: + - "10.96.0.0/12" + +# EKS cluster parameters +region: "" +sshKeyName: "" +publicIP: false + +clusterIdentity: + name: "aws-cluster-identity" + kind: "AWSClusterStaticIdentity" + +# EKS machines parameters +worker: + amiID: "" + iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io + instanceType: "t3.small" + rootVolumeSize: 30 + imageLookup: + format: "" + org: "" + baseOS: "" + +# Kubernetes version +kubernetes: + version: v1.30.4 diff --git a/templates/provider/cluster-api-provider-aws/Chart.yaml b/templates/provider/cluster-api-provider-aws/Chart.yaml index 1b5fb9bdd..1645247aa 100644 --- a/templates/provider/cluster-api-provider-aws/Chart.yaml +++ b/templates/provider/cluster-api-provider-aws/Chart.yaml @@ -21,3 +21,5 @@ version: 0.0.1 appVersion: "2.6.1" annotations: hmc.mirantis.com/infrastructure-providers: aws + hmc.mirantis.com/controlplane-providers: eks + hmc.mirantis.com/bootstrap-providers: eks diff --git a/templates/provider/hmc-templates/files/templates/aws-eks-0-0-1.yaml b/templates/provider/hmc-templates/files/templates/aws-eks-0-0-1.yaml new file mode 100644 index 000000000..453af94ae --- /dev/null +++ b/templates/provider/hmc-templates/files/templates/aws-eks-0-0-1.yaml @@ -0,0 +1,10 @@ +apiVersion: hmc.mirantis.com/v1alpha1 +kind: ClusterTemplate +metadata: + name: aws-eks-0-0-1 + annotations: + helm.sh/resource-policy: keep +spec: + helm: + chartName: aws-eks + chartVersion: 0.0.1