How-To Enable or Disable MetalLB via Sunpike API For an Already Installed Cluster
Problem
How-To Add Enable or Disable MetalLB via Sunpike API For an Already Installed Cluster?
Environment
- Platform9 Managed Kubernetes - v5.2 and K8s v1.20 and Higher
Procedure
- Fetch the authentication TOKEN.
- Keystone Identity API: This link describes the process for getting a Keystone authentication token in order to access the PMK REST API.
- Make use of either the below mentioned API call to check if the cluster already has MetalLB enabled or not.
curl -X GET -H "X-Auth-Token: $TOKEN" https://<DU_FQDN>/qbert/v4/<PROJECT_ID>/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/<CLUSTER_UUID>-metallb | jq
- For the cluster that does not have MetalLB enabled, the below output will be presented.
# curl -k -X GET -H "X-Auth-Token: $TOKEN" https://airctl-1.pf9.localnet/qbert/v4/510ccf9d2b044f8aa28143e58ba47e5f/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/5685f4e4-8d34-43d6-8006-8829200bfd3c-metallb | jq
...
...
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "clusteraddons.sunpike.platform9.com \"5685f4e4-8d34-43d6-8006-8829200bfd3c-metallb\" not found",
"reason": "NotFound",
"details": {
"name": "5685f4e4-8d34-43d6-8006-8829200bfd3c-metallb",
"group": "sunpike.platform9.com",
"kind": "clusteraddons"
},
"code": 404
}
- To enable MetalLB for this cluster create a new JSON spec for MetalLB.
# cat metallb.json
{
"apiVersion": "sunpike.platform9.com/v1alpha2",
"kind": "ClusterAddon",
"metadata": {
"labels": {
"sunpike.pf9.io/cluster": "CLUSTER_UUID",
"type": "metallb"
},
"name": "CLUSTER_UUID-metallb",
"namespace": "default"
},
"spec": {
"clusterID": "CLUSTER_UUID",
"override": {
"params": [
{
"name": "MetallbIpRange",
"value": "10.128.147.250-10.128.147.251"
}
]
},
"type": "metallb",
"version": "0.9.6",
"watch": false
}
}
The metallb version in the above JSON file is currently on 0.9.6. It will be updated along with the pf9-kube
version and can be referred from the Support Matrix.
- To Enable MetalLB ClusterAddon object with the above-mentioned new JSON spec metallbspec.json.
# curl -X POST -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -d "@metallb.json" $DU_FQDN/qbert/v4/$PROJECT_ID/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons
Replace the placeholders: <DU_FQDN>
, <PROJECT_ID>
and the <CLUSTER_UUID>
with their appropriate values wherever required.
The "name" attribute in the spec must be in the format CLUSTER_UUID-metallb
Also,MetallbIpRange
value should be set with the required set of IP addresses.
- The API call mentioned below can be referred as an example for the one above.
# curl -X POST -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -d "@metallb.json" https://airctl-1.pf9.localnet/qbert/v4/510ccf9d2b044f8aa28143e58ba47e5f/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons
- Verify whether MetalLB is now enabled.
x
# curl -k -X GET -H "X-Auth-Token: $TOKEN" https://airctl-1.pf9.localnet/qbert/v4/510ccf9d2b044f8aa28143e58ba47e5f/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/5685f4e4-8d34-43d6-8006-8829200bfd3c-metallb | jq
{
"kind": "ClusterAddon",
"apiVersion": "sunpike.platform9.com/v1alpha2",
"metadata": {
...
"spec": {
"clusterID": "5685f4e4-8d34-43d6-8006-8829200bfd3c",
"version": "0.9.6",
"type": "metallb",
"override": {
"params": [
{
"name": "MetallbIpRange",
"value": "10.128.147.250-10.128.147.251"
}
]
},
"watch": true
},
"status": {
"phase": "Installed",
"lastChecked": null
}
}
# kubectl get clusteraddons --kubeconfig='/etc/sunpike/kubeconfig'
NAME CLUSTER TYPE PHASE CREATED AT
5685f4e4-8d34-43d6-8006-8829200bfd3c-coredns 5685f4e4-8d34-43d6-8006-8829200bfd3c coredns Installed 2021-11-18T06:11:37Z
5685f4e4-8d34-43d6-8006-8829200bfd3c-kubernetes-dashboard 5685f4e4-8d34-43d6-8006-8829200bfd3c kubernetes-dashboard Installed 2021-11-18T06:11:37Z
5685f4e4-8d34-43d6-8006-8829200bfd3c-metrics-server 5685f4e4-8d34-43d6-8006-8829200bfd3c metrics-server Installed 2021-11-18T06:11:37Z
5685f4e4-8d34-43d6-8006-8829200bfd3c-metallb 5685f4e4-8d34-43d6-8006-8829200bfd3c metallb Installed 2021-11-18T10:37:47Z
- To Disable MetalLB for a Cluster that already has it enabled, use the API call below.
# curl -X DELETE -H "X-Auth-Token: $TOKEN" $DU_FQDN/qbert/v4/$PROJECT_ID/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/<CLUSTER_UUID>-metallb
- The API call mentioned below can be referred as an example for the one above.
# curl -X DELETE -H "X-Auth-Token: $TOKEN" https://airctl-1.pf9.localnet/qbert/v4/510ccf9d2b044f8aa28143e58ba47e5f/sunpike/apis/sunpike.platform9.com/v1alpha2/namespaces/default/clusteraddons/5685f4e4-8d34-43d6-8006-8829200bfd3c-metallb
Was this page helpful?