Table of Contents generated with DocToc
- Kubernetes Cluster API Provider IBM Cloud
This repository hosts a concrete implementation of an IBM Cloud provider for the cluster-api project.
The Cluster API brings declarative, Kubernetes-style APIs to cluster creation, configuration and management. The API itself is shared across multiple cloud providers allowing for true IBM Cloud hybrid deployments of Kubernetes.
- Install
kubectl
(see here). Becausekustomize
was included intokubectl
and it's used bycluster-api-provider-ibmcloud
in generating yaml files, so version1.14.0+
ofkubectl
is required, see integrate kustomize into kubectl for more info. - You can use either VM, container or existing Kubernetes cluster act as the bootstrap cluster.
- Install a driver if you are using minikube. For Linux, we recommend kvm2. For MacOS, we recommend VirtualBox.
- An appropriately configured Go development environment
- Install
clusterctl
tool (see here)
-
Build a qcow2 image suitable for use as a Kubernetes cluster machine as detailed in the image builder book.
Note: Rename the output image to add the
.qcow2
extension. This is required by the next step. -
Create a VPC Gen2 custom image based on the qcow2 image built in the previous step as detailed in the VPC documentation.
-
Create simple, local bootstrap cluster with a control-plane and worker node
Using kind:
~ kind create cluster --name my-bootstrap --config bootstrap.yaml
Example bootstrap.yaml:
kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker
Make sure the nodes are in
Ready
state before moving on.~ kubectl get nodes NAME STATUS ROLES AGE VERSION my-bootstrap-control-plane Ready control-plane,master 46h v1.20.2 my-bootstrap-worker Ready <none> 46h v1.20.2
-
Apply IBM VPC CAPI CRDs
~ kubectl apply -f config/crd/bases
Output:
customresourcedefinition.apiextensions.k8s.io/ibmvpcclusters.infrastructure.cluster.x-k8s.io created customresourcedefinition.apiextensions.k8s.io/ibmvpcmachines.infrastructure.cluster.x-k8s.io created customresourcedefinition.apiextensions.k8s.io/ibmvpcmachinetemplates.infrastructure.cluster.x-k8s.io created
-
Initialize local bootstrap cluter as a management cluster
This cluster will be used to provision a workload cluster in IBM Cloud.
~ clusterctl init
Output:
Fetching providers Installing cert-manager Version="v1.1.0" Waiting for cert-manager to be available... Installing Provider="cluster-api" Version="v0.3.16" TargetNamespace="capi-system" Installing Provider="bootstrap-kubeadm" Version="v0.3.16" TargetNamespace="capi-kubeadm-bootstrap-system" Installing Provider="control-plane-kubeadm" Version="v0.3.16" TargetNamespace="capi-kubeadm-control-plane-system" Your management cluster has been initialized successfully! You can now create your first workload cluster by running the following: clusterctl config cluster [name] --kubernetes-version [version] | kubectl apply -f -
-
Set workload cluster environment variables
The sample IAM_ENDPOINT below points to Production and the SERVICE_ENDPOINT points to the
us-east
VPC region. Make sure these values reflect your target VPC environment in IBM Cloud.export IAM_ENDPOINT=https://iam.cloud.ibm.com/identity/token export SERVICE_ENDPOINT=https://us-south.iaas.cloud.ibm.com/v1 export API_KEY=<YOUR_API_KEY>
-
Run IBM provider controllers
The controllers will run against your local management bootstrap cluster.
~ make run
-
Provision workload cluster in IBM Cloud
You can use clusterctl to render the yaml through templates.
Note: the
IBMVPC_IMAGE_ID
value below should reflect the ID of the custom qcow2 imageIBMVPC_REGION=us-south \ IBMVPC_ZONE=us-south-1 \ IBMVPC_RESOURCEGROUP=4f15679623607b855b1a27a67f20e1c7 \ IBMVPC_NAME=ibm-vpc-0 \ IBMVPC_IMAGE_ID=r134-ea84bbec-7986-4ff5-8489-d9ec34611dd4 \ IBMVPC_PROFILE=bx2-4x16 \ IBMVPC_SSHKEY_ID=r134-2a82b725-e570-43d3-8b23-9539e8641944 \ clusterctl generate cluster ibm-vpc-0 --kubernetes-version v1.19.9 \ --target-namespace default \ --control-plane-machine-count=1 \ --worker-machine-count=2 \ --from ./templates/cluster-template.yaml | kubectl apply -f -
Output:
cluster.cluster.x-k8s.io/ibm-vpc-5 created ibmvpccluster.infrastructure.cluster.x-k8s.io/ibm-vpc-5 created kubeadmcontrolplane.controlplane.cluster.x-k8s.io/ibm-vpc-5-control-plane created ibmvpcmachinetemplate.infrastructure.cluster.x-k8s.io/ibm-vpc-5-control-plane created machinedeployment.cluster.x-k8s.io/ibm-vpc-5-md-0 created ibmvpcmachinetemplate.infrastructure.cluster.x-k8s.io/ibm-vpc-5-md-0 created kubeadmconfigtemplate.bootstrap.cluster.x-k8s.io/ibm-vpc-5-md-0 created
-
Deploy Container Network Interface (CNI)
Example: calico
kubectl apply -f https://docs.projectcalico.org/v3.15/manifests/calico.yaml
-
Check the state of the provisioned cluster and machine objects within the local management cluster
Clusters
~ kubectl get clusters NAME PHASE ibm-vpc-0 Provisioned
Kubeadm Control Plane
~ kubectl get kubeadmcontrolplane NAME INITIALIZED API SERVER AVAILABLE VERSION REPLICAS READY UPDATED UNAVAILABLE ibm-vpc-0-control-plane true true v1.19.9 1 1 1
Machines
~ kubectl get machines ibm-vpc-0-control-plane-vzz47 ibmvpc://ibm-vpc-0/ibm-vpc-0-control-plane-rg6xv Running v1.19.9 ibm-vpc-0-md-0-5444cfcbcd-6gg5z ibmvpc://ibm-vpc-0/ibm-vpc-0-md-0-dbxb7 Running v1.19.9 ibm-vpc-0-md-0-5444cfcbcd-7kr9x ibmvpc://ibm-vpc-0/ibm-vpc-0-md-0-k7blr Running v1.19.9
-
Check the state of the newly provisioned cluster within IBM Cloud
~ clusterctl get kubeconfig ibm-vpc-0 > ~/.kube/ibm-vpc-0 ~ export KUBECONFIG=~/.kube/ibm-vpc-0 ~ kubectl get nodes NAME STATUS ROLES AGE VERSION ibm-vpc-0-control-plane-rg6xv Ready master 41h v1.18.15 ibm-vpc-0-md-0-4dc5c Ready <none> 41h v1.18.15 ibm-vpc-0-md-0-dbxb7 Ready <none> 20h v1.18.15
-
Experiment with machinedeployment alterations in your management cluster
With your management (local) and workload (IBM Cloud) clusters successfully provisioned, you can now experiment with altering the number of machine deployment replicas in your management cluster and see the replica counts reconciled in your workload cluster.
~ kubectl get machinedeployments NAME PHASE REPLICAS READY UPDATED UNAVAILABLE ibm-vpc-0-md-0 Running 2 2 2 ~ kubectl scale machinedeployment ibm-vpc-0-md-0 --replicas 3
Increase / decrease the
replicas: 2
count in the spec section to see the machine replicas reconciled within the workload cluster.
If you have questions or want to get the latest project news, you can connect with us in the following ways:
- Chat with us on the Kubernetes Slack in the #cluster-api-ibmcloud channel
- Subscribe to the SIG Cluster Lifecycle Google Group for access to documents and calendars
- Join our Weekly meeting sessions where we share the latest project news, demos, answer questions, and triage issues
Pull Requests and feedback on issues are very welcome! See the issue tracker if you're unsure where to start, especially the Good first issue and Help wanted tags, and also feel free to reach out to discuss.
See also our contributor guide and the Kubernetes community page for more details on how to get involved.
Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.