-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
2,260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
cluster-autoscaler/cloudprovider/builder/builder_linode.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// +build linode | ||
|
||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builder | ||
|
||
import ( | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider" | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/linode" | ||
"k8s.io/autoscaler/cluster-autoscaler/config" | ||
) | ||
|
||
// AvailableCloudProviders supported by the cloud provider builder. | ||
var AvailableCloudProviders = []string{ | ||
cloudprovider.LinodeProviderName, | ||
} | ||
|
||
// DefaultCloudProvider for linode-only build is linode. | ||
const DefaultCloudProvider = cloudprovider.LinodeProviderName | ||
|
||
func buildCloudProvider(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider { | ||
switch opts.CloudProviderName { | ||
case cloudprovider.LinodeProviderName: | ||
return linode.BuildLinode(opts, do, rl) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Cluster Autoscaler for Linode | ||
|
||
The cluster autoscaler for Linode scales nodes in a LKE cluster. | ||
|
||
## Linode Kubernetes Engine | ||
|
||
Linode Kubernetes Engine ([LKE](https://www.linode.com/docs/guides/deploy-and-manage-a-cluster-with-linode-kubernetes-engine-a-tutorial/)) is the managed K8s solution provided by Linode. | ||
|
||
LKE lets users create Node Pools, i.e. groups of nodes (also called Linodes) each of the same type. | ||
|
||
The size of a Node Pool can be configured at any moment. The user cannot select specific nodes to be deleted when downsizing a Node Pool, rather, Linode will randomly select nodes to be deleted to reach the defined size, even if a node is not healthy or has been manually deleted. | ||
|
||
Nodes in a Node Pool are considered disposable: they can be deleted and recreated at any moment, deleting a single node or using the *recycle* feature, on these cases the node will be recreated by Linode after a small amount of time. | ||
|
||
Node Pools do not support user defined tags or labels. | ||
|
||
There is no limitation on the number of Node Pool a LKE Cluster can have, limited to the maximum number of nodes an LKE Cluster can have. | ||
|
||
## Cluster Autoscaler | ||
|
||
A cluster autoscaler node group is composed of multiple LKE Node Pools of the same Linode type (e.g. g6-standard-1, g6-standard-2), each holding a *single* Linode. | ||
|
||
At every scan interval the cluster autoscaler reviews every LKE Node Pool and if: | ||
* it is not among the ones to be excluded as defined in the configuration file; | ||
* it holds a single Linode; | ||
|
||
then it becomes part of the node group holding LKE Node Pools of the Linode type it has, or a node group is created with this LKE Node Pool inside if there are no node groups with that Linode type at the moment. | ||
|
||
Scaling is achieved adding LKE Node Pools to node groups, *not* increasing the size of a LKE Node Pool, that must stay 1. The reason behind this is that Linode does not provide a way to selectively delete a Linode from a LKE Node Pool and decrease the size of the pool with it. | ||
|
||
This is also the reason we cannot use the standard `nodes` and `node-group-auto-discovery` cluster autoscaler flag (no labels could be used to select a specific node group), and the reason why there can be no node group of the same type. | ||
|
||
## Configuration | ||
|
||
The cluster autoscaler automatically select every LKE Node Pool that is part of a LKE cluster, so there is no need define the `node-group-auto-discovery` or `nodes` flags, see [examples/cluster-autoscaler-autodiscover.yaml](examples/cluster-autoscaler-autodiscover.yaml) for an example of a kubernetes deployment. | ||
|
||
It is mandatory to define the cloud configuration file `cloud-config`. | ||
You can see an example of the cloud config file at [examples/cluster-autoscaler-secret.yaml](examples/cluster-autoscaler-secret.yaml), it is an INI file with the following fields: | ||
|
||
| Key | Value | Mandatory | Default | | ||
|-----|-------|-----------|---------| | ||
| global/linode-token | Linode API Token with Read/Write permission for Kubernetes and Linodes | yes | none | | ||
| global/lke-cluster-id | ID of the LKE cluster (numeric of the form: 12345, you can get this via `linode-cli` or looking at the first number of a linode in a pool, e.g. for lke15989-19461-5fec9212fad2 the lke-cluster-id is "15989") | yes | none | | ||
| global/defaut-min-size-per-linode-type | minimum size of a node group (must be > 0) | no | 1 | | ||
| global/defaut-max-size-per-linode-type | maximum size of a node group | no | 254 | | ||
| global/do-not-import-pool-id | Pool id (numeric of the form: 12345) that will be excluded from the pools managed by the cluster autoscaler; can be repeated | no | none | ||
| nodegroup \"linode_type\"/min-size" | minimum size for a specific node group | no | global/defaut-min-size-per-linode-type | | ||
| nodegroup \"linode_type\"/max-size" | maximum size for a specific node group | no | global/defaut-min-size-per-linode-type | | ||
|
||
Log levels of intertest for the Linode provider are: | ||
* 1 (flag: ```--v=1```): basic logging at start; | ||
* 2 (flag: ```--v=2```): logging of the node group composition at every scan; | ||
|
||
## Development | ||
|
||
Make sure you are inside the `cluster-autoscaler` path of the [autoscaler repository](https://github.com/kubernetes/autoscaler). | ||
|
||
Create the docker image: | ||
``` | ||
make container | ||
``` | ||
tag the generated docker image and push it to a registry. |
9 changes: 9 additions & 0 deletions
9
cluster-autoscaler/cloudprovider/linode/examples/cluster-autoscale-pdb.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: policy/v1beta1 | ||
kind: PodDisruptionBudget | ||
metadata: | ||
name: cluster-autoscaler-pdb | ||
spec: | ||
minAvailable: 1 | ||
selector: | ||
matchLabels: | ||
app: cluster-autoscaler |
169 changes: 169 additions & 0 deletions
169
cluster-autoscaler/cloudprovider/linode/examples/cluster-autoscaler-autodiscover.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
labels: | ||
k8s-addon: cluster-autoscaler.addons.k8s.io | ||
k8s-app: cluster-autoscaler | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: cluster-autoscaler | ||
labels: | ||
k8s-addon: cluster-autoscaler.addons.k8s.io | ||
k8s-app: cluster-autoscaler | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["events", "endpoints"] | ||
verbs: ["create", "patch"] | ||
- apiGroups: [""] | ||
resources: ["pods/eviction"] | ||
verbs: ["create"] | ||
- apiGroups: [""] | ||
resources: ["pods/status"] | ||
verbs: ["update"] | ||
- apiGroups: [""] | ||
resources: ["endpoints"] | ||
resourceNames: ["cluster-autoscaler"] | ||
verbs: ["get", "update"] | ||
- apiGroups: [""] | ||
resources: ["nodes"] | ||
verbs: ["watch", "list", "get", "update"] | ||
- apiGroups: [""] | ||
resources: | ||
- "pods" | ||
- "services" | ||
- "replicationcontrollers" | ||
- "persistentvolumeclaims" | ||
- "persistentvolumes" | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["extensions"] | ||
resources: ["replicasets", "daemonsets"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["policy"] | ||
resources: ["poddisruptionbudgets"] | ||
verbs: ["watch", "list"] | ||
- apiGroups: ["apps"] | ||
resources: ["statefulsets", "replicasets", "daemonsets"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["storage.k8s.io"] | ||
resources: ["storageclasses", "csinodes"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["batch", "extensions"] | ||
resources: ["jobs"] | ||
verbs: ["get", "list", "watch", "patch"] | ||
- apiGroups: ["coordination.k8s.io"] | ||
resources: ["leases"] | ||
verbs: ["create"] | ||
- apiGroups: ["coordination.k8s.io"] | ||
resourceNames: ["cluster-autoscaler"] | ||
resources: ["leases"] | ||
verbs: ["get", "update"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
labels: | ||
k8s-addon: cluster-autoscaler.addons.k8s.io | ||
k8s-app: cluster-autoscaler | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
verbs: ["create","list","watch"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
resourceNames: ["cluster-autoscaler-status", "cluster-autoscaler-priority-expander"] | ||
verbs: ["delete", "get", "update", "watch"] | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: cluster-autoscaler | ||
labels: | ||
k8s-addon: cluster-autoscaler.addons.k8s.io | ||
k8s-app: cluster-autoscaler | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-autoscaler | ||
subjects: | ||
- kind: ServiceAccount | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
labels: | ||
k8s-addon: cluster-autoscaler.addons.k8s.io | ||
k8s-app: cluster-autoscaler | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: cluster-autoscaler | ||
subjects: | ||
- kind: ServiceAccount | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
|
||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: cluster-autoscaler | ||
template: | ||
metadata: | ||
labels: | ||
app: cluster-autoscaler | ||
annotations: | ||
prometheus.io/scrape: 'true' | ||
prometheus.io/port: '8085' | ||
spec: | ||
serviceAccountName: cluster-autoscaler | ||
containers: | ||
- image: k8s.gcr.io/autoscaling/cluster-autoscaler:latest | ||
name: cluster-autoscaler | ||
resources: | ||
limits: | ||
cpu: 100m | ||
memory: 300Mi | ||
requests: | ||
cpu: 100m | ||
memory: 300Mi | ||
command: | ||
- ./cluster-autoscaler | ||
- --v=2 | ||
- --cloud-provider=linode | ||
- --cloud-config=/config/cloud-config | ||
volumeMounts: | ||
- name: ssl-certs | ||
mountPath: /etc/ssl/certs/ca-certificates.crt | ||
readOnly: true | ||
- name: cloud-config | ||
mountPath: /config | ||
readOnly: true | ||
imagePullPolicy: "Always" | ||
volumes: | ||
- name: ssl-certs | ||
hostPath: | ||
path: "/etc/ssl/certs/ca-certificates.crt" | ||
- name: cloud-config | ||
secret: | ||
secretName: cluster-autoscaler-cloud-config |
26 changes: 26 additions & 0 deletions
26
cluster-autoscaler/cloudprovider/linode/examples/cluster-autoscaler-secret.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: cluster-autoscaler-cloud-config | ||
namespace: kube-system | ||
type: Opaque | ||
stringData: | ||
cloud-config: |- | ||
[global] | ||
linode-token=55b4c52123462dk23sa165cc3dba1234123125666f1422c8 | ||
lke-cluster-id=12345 | ||
defaut-min-size-per-linode-type=1 | ||
defaut-max-size-per-linode-type=10 | ||
do-not-import-pool-id=19462 | ||
do-not-import-pool-id=19763 | ||
[nodegroup "g6-standard-1"] | ||
min-size=2 | ||
max-size=5 | ||
[nodegroup "g6-standard-2"] | ||
max-size=4 | ||
[nodegroup "g6-standard-4"] | ||
max-size=2 |
Oops, something went wrong.