项目作者: plunder-app

项目描述 :
A bare metal provider for the Kubernetes Cluster API
高级语言: Go
项目地址: git://github.com/plunder-app/cluster-api-plunder.git
创建时间: 2019-08-21T12:50:33Z
项目社区:https://github.com/plunder-app/cluster-api-plunder

开源协议:

下载


cluster-api-plunder

Pronounced: ClustARRRR-APIARRRR-plunder.

Warning: This provider is so untested that I would only recommend using it against your worst enemies, that being said.. if you’re feeling brave then be my guest :D

What is it?

The cluster-api-plunder is a Cluster-API provider that extends the capabilities of a Kubernetes cluster so that it can be used to not only manage the provisioning of applications and services, but also the provisioning of actual infrastructure to host additional Kubernetes clusters.

This provider does this by “translating” infrastructure requests from Cluster-API and using plunder to provision clusters and the required machines that make up a complete Kubernetes cluster.

How it works

Cloud environments typically have a massive agile advantage when it comes to provisioning infrastructure, typically the ground work (bare-metal provisioning) it already taken care of (I’m presuming through the automation of api-human). Meaning that when you ask for some infrastructure then the cloud provider will be cloning VM templates etc.. to quickly get some machine infrastructure back to you.

Bare-Metal

In order to handle quick provisioning today plunder watches for machines starting up that typically are blank/new and need to try and boot, it will register their MAC addresses and place them in a reboot loop (until we need them).

  1. $ pldrctl get unleased
  2. Mac Address Hardware Vendor Time Seen Time since
  3. 00:50:56:a5:11:20 VMware, Inc. Sun Nov 3 10:54:18 2019 0s
  4. 00:50:56:a5:b5:f1 VMware, Inc. Sun Nov 3 10:54:18 2019 0s

NOTE: There are more efficent ways of doing this, just haven’t had the time ¯\_(ツ)_/¯

When it comes to provisioning, we simply flip a server from reboot to provision and “hey presto”

Using it

At the moment, there is still a few steps that are needed to get this all up and running and i’ve yet to get the provider in a kubernetes deployment (someone feel free to raise an issue).

Add Plunder Client Certificate

Add the seret that will contain the plunder config, the --from-file should point to the location of the client certificate.

  1. k create secret generic plunder --from-file=./plunderclient.yaml --namespace=capi-system

Install CRDs

To use the created ones:

  1. kubectl apply -f https://github.com/plunder-app/cluster-api-plunder/raw/master/cluster-api-plunder-components.yaml

To generate them within the source code / project:

  1. make install

Then verify them with kubectl get crds | grep plunder.

Install/Run Controller

If you are using the manifest that is part of this repository and have created the certificate, then the controller should be up and running as expected.

Alternatively you can build/run the controller locally as detailed below

Build/Run Controller

Copy the plunderclient.yaml file to the same location that the controller will run.

make run will then start the controller.

Cluster Definition

Cluster.yaml should typically look like below the cidrBlocks will define the range of addresses used by pods started within the cluster.

  1. apiVersion: cluster.x-k8s.io/v1alpha2
  2. kind: Cluster
  3. metadata:
  4. name: cluster-plunder
  5. spec:
  6. clusterNetwork:
  7. pods:
  8. cidrBlocks: ["192.168.0.0/16"]
  9. infrastructureRef:
  10. apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
  11. kind: PlunderCluster
  12. name: cluster-plunder
  13. ---
  14. apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
  15. kind: PlunderCluster
  16. metadata:
  17. name: cluster-plunder

Machine Definition

IPAM isn’t completed (lol.. it’s not started), so currently you’ll need to specify addresses for machines, this will need fixing for machineSets

Also:

  • In plunderMachine.spec => deploymentType is required in order for Plunder to know what to provision.
  • In machine.spec => version is required to determine the version of Kubernetes to provision.

Machine.yaml should looks something like below:

  1. apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
  2. kind: PlunderMachine
  3. metadata:
  4. name: controlplane
  5. namespace: default
  6. spec:
  7. ipaddress: 192.168.1.123
  8. deploymentType: preseed
  9. ---
  10. apiVersion: cluster.x-k8s.io/v1alpha2
  11. kind: Machine
  12. metadata:
  13. labels:
  14. cluster.x-k8s.io/cluster-name: cluster-plunder
  15. cluster.x-k8s.io/control-plane: "true"
  16. name: controlplane
  17. namespace: default
  18. spec:
  19. version: "v1.14.2"
  20. bootstrap:
  21. data: ""
  22. infrastructureRef:
  23. apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
  24. kind: PlunderMachine
  25. name: controlplane
  26. namespace: default
  27. ---
  28. apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
  29. kind: PlunderMachine
  30. metadata:
  31. name: worker
  32. namespace: default
  33. spec:
  34. ipaddress: 192.168.1.124
  35. deploymentType: preseed
  36. ---
  37. apiVersion: cluster.x-k8s.io/v1alpha2
  38. kind: Machine
  39. metadata:
  40. labels:
  41. cluster.x-k8s.io/cluster-name: cluster-plunder
  42. name: worker
  43. namespace: default
  44. spec:
  45. version: "v1.14.2"
  46. bootstrap:
  47. data: ""
  48. infrastructureRef:
  49. apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
  50. kind: PlunderMachine
  51. name: worker
  52. namespace: default

Deploy in Kubernetes

The same manifests are in examples/simple and can be deployed through kubectl with the command:

kubectl -f examples/simple/cluster.yaml and kubectl create -f examples/simple/machine.yaml

Watching the deployment

Machine State

  1. k get machines
  2. NAME PROVIDERID PHASE
  3. controlplane provisioning
  4. worker provisioning
  5. < 7-ish mins later>
  6. k get machines
  7. NAME PROVIDERID PHASE
  8. controlplane plunder://00:50:56:a5:b5:f1 provisioned
  9. worker plunder://00:50:56:a5:11:20 provisioned

Machine Events

  1. k get events
  2. LAST SEEN TYPE REASON OBJECT MESSAGE
  3. 50m Warning No Hardware found plundermachine/controlplane Plunder has no available hardware to provision
  4. 47m Normal PlunderProvision plundermachine/controlplane Plunder has begun provisioning the Operating System
  5. 40m Normal PlunderProvision plundermachine/controlplane Host has been succesfully provisioned OS in 7m1s Seconds
  6. 40m Normal PlunderProvision plundermachine/worker Plunder has begun provisioning the Operating System
  7. 33m Normal PlunderProvision plundermachine/worker Host has been succesfully provisioned OS in 7m6s Seconds

Deleting Machines

There are two methods for removing the deployed machines:

kubectl delete machines --all or kubectl delete -f ./examples/simple/machine.yaml

This process will wipe the boot sector and beginning of the disk which will result in it booting into a “blank enough” state for plunder to add it back to the reboot loop.