Declarative
A common pattern is for users to use Terraform to provision Kubernetes clusters perhaps using a Jenkins based pipeline. These brownfield clusters can then be imported into the controller.
Typical Automation Sequence¶
The image below showcases a Jenkins based "pipeline" that automates the following steps.
- Uses Terraform to provision a Kubernetes cluster based on a version controlled cluster spec in a Git repo.
- Imports the raw Kubernetes cluster into the Controller
- Brings the cluster to a state of compliance with specified cluster blueprint.
Cluster Specification¶
Create and manage version controlled, declarative specifications for your clusters. Example cluster specifications are available in this public Git repo.
V1 Cluster Spec¶
Example 1
In the example below, the cluster will be provided a name "eks-dev" in the Controller. It will be imported into the "default_project" and be provisioned with the "default" cluster blueprint.
kind: Cluster
metadata:
name: eks-dev
project: default_project
spec:
type: imported
blueprint: default
blueprintversion: Latest
location: aws/us-west-2
Example 2
In the example below, the cluster will be provided a name "aks-qa" in the Controller. It will be imported into the "qa project" and be provisioned with the "qa" cluster blueprint.
kind: Cluster
metadata:
name: aks-qa
project: qa
spec:
type: imported
blueprint: qa
blueprintversion: Latest
location: aws/us-west-2
V3 Cluster Spec¶
apiVersion: infra.k8smgmt.io/v3
kind: Cluster
metadata:
name: demo-imported-v3-aks
project: demo
spec:
blueprintConfig:
name: minimal
config:
kubernetesProvider: AKS
location: azure/centralindia
provisionEnvironment: CLOUD
proxyConfig: {}
type: imported
Create Cluster¶
For imported clusters, creating a cluster using a "cluster specification" file will return a cryptographically unique "bootstrap" YAML file.
rctl create cluster -f clusterspec.yaml
Use "kubectl" to apply the bootstrap YAML file on your existing clusters to import it into the controller. Note that every cluster needs a different bootstrap YAML file and it is not possible to reuse it across clusters.
kubectl apply -f cluster_bootstrap.yaml
Important
The cluster will be created in the project in the cluster specification.
List Clusters¶
To retrieve a specific imported cluster, use the below command
./rctl get cluster <importedcluster_name>
Output
./rctl get cluster demo-importedcluster
+------------------------+-----------+-----------+---------------------------+
| NAME | TYPE | OWNERSHIP | PROVISION STATUS |
+------------------------+-----------+-----------+---------------------------+
| demo-importedcluster | imported | self | |
+------------------------+-----------+-----------+---------------------------+
To retrieve a specific v3 cluster details, use the below command
./rctl get cluster demo-importedcluster --v3
Example
./rctl get cluster demo-importedcluster --v3
+------------------------+-------------------------------+-----------+----------+-----------+---------------------------+
| NAME | CREATED AT | OWNERSHIP | TYPE | BLUEPRINT | PROVISION STATUS |
+------------------------+-------------------------------+-----------+----------+-----------+---------------------------+
| demo-importedcluster | 2023-06-05 10:54:08 +0000 UTC | self | imported | | |
+------------------------+-------------------------------+-----------+----------+-----------+---------------------------+
To view the entire v3 cluster config spec, use the below command
./rctl get cluster <importedcluster_name> --v3 -o json
(or)
./rctl get cluster <importedcluster_name> --v3 -o yaml
Download Cluster Config¶
Use the below command to download an imported Cluster Config file
./rctl get cluster config <ClusterName> <ClusterConfigFileName.yaml>
Example:
/rctl get cluster config demo-imported demo-importedcluster-config.yaml
To download a v3 cluster config, use the below command
./rctl get cluster config <cluster-name> --v3
Important
Download the cluster configuration only after the cluster is completely provisioned
Delete Cluster¶
Already imported clusters can be deleted using the RCTL CLI. Note that this operation only deletes the cluster instance on the controller. The cluster administrator needs to manually delete the final remnants of the k8s operator on imported clusters.
rctl delete cluster <name of cluster>
Jenkins Example¶
Here is an example Jenkins pipeline to import an existing Kubernetes cluster into a specific project.