-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rancher as a cloud provider #4041
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a97eeee
feat(cloudprovider): Implement rancher as a cloud provider.
f3d2cb3
sync upstream.
douglasmakey 962f302
feat(cloudprovider.rancher): update readme.
douglasmakey 5c25f94
feat(cloudprovider.rancher): Add owners file.
douglasmakey 9a8c4e7
fix(cloudprovider.rancher): fix typo
douglasmakey 5904ddb
Update OWNERS
patrickdappollonio 63dc1d1
Update OWNERS file.
patrickdappollonio f1978a7
Delete OWNERS
douglasmakey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_rancher.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 rancher | ||
|
||
/* | ||
Copyright 2021 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/rancher" | ||
"k8s.io/autoscaler/cluster-autoscaler/config" | ||
) | ||
|
||
// AvailableCloudProviders supported by the rancher provider builder. | ||
var AvailableCloudProviders = []string{ | ||
cloudprovider.RancherProviderName, | ||
} | ||
|
||
// DefaultCloudProvider for do-only build is rancher. | ||
const DefaultCloudProvider = cloudprovider.RancherProviderName | ||
|
||
func buildCloudProvider(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider { | ||
switch opts.CloudProviderName { | ||
case cloudprovider.RancherProviderName: | ||
return rancher.BuildRancher(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,54 @@ | ||
# Cluster Autoscaler for Rancher | ||
|
||
The cluster autoscaler for Rancher scales nodes within any specified Rancher Kubernetes Engine cluster's node pool. | ||
|
||
# Requirements | ||
|
||
Rancher version >= 2.5.6 | ||
|
||
# Configuration | ||
|
||
The cluster-autoscaler for Rancher needs a configuration file to work by using --cloud-config parameter. | ||
|
||
Here an [example](examples/autoscaler-config-example.yaml). | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: cluster-autoscaler-cloud-config | ||
namespace: kube-system | ||
type: Opaque | ||
stringData: | ||
cloud-config: |- | ||
[Global] | ||
url=https://rancherapi.com/v3 | ||
access=your-token | ||
secret=your-secret | ||
cluster-id=c-abcdef | ||
autoscaler_node_arg: "2:6:c-abcdef:np-abcde" # Your NodePool ID | ||
``` | ||
|
||
You have to create a new API Key from your Rancher Dashboard to get the `access` and `secret` values to use the Autoscaler. | ||
|
||
# Development | ||
|
||
Make sure you're inside the root path of the [autoscaler repository](https://github.com/kubernetes/autoscaler) | ||
|
||
1.) Build the `cluster-autoscaler` binary: | ||
|
||
``` | ||
make build-in-docker | ||
``` | ||
|
||
2.) Build the docker image: | ||
|
||
``` | ||
docker build -t rancher/cluster-autoscaler:dev . | ||
``` | ||
|
||
3.) Push the docker image to Docker hub: | ||
|
||
``` | ||
docker push rancher/cluster-autoscaler:dev | ||
``` | ||
14 changes: 14 additions & 0 deletions
14
cluster-autoscaler/cloudprovider/rancher/examples/autoscaler-config-example.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,14 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: cluster-autoscaler-cloud-config | ||
namespace: kube-system | ||
type: Opaque | ||
stringData: | ||
cloud-config: |- | ||
[Global] | ||
url=https://rancherapi.com/v3 | ||
access=token-abcdef | ||
secret=ksjdhfiusdhfkjsdfhisudhfnskjdfhskjdfhksdjfhksjdfhksdjf | ||
cluster-id=c-abcdef | ||
autoscaler_node_arg: "2:6:c-abcdef:np-abcde" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: new line |
118 changes: 118 additions & 0 deletions
118
cluster-autoscaler/cloudprovider/rancher/examples/autoscaler-noconfig-template.txt
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,118 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems it ends with txt. is it used for rendering templates? |
||
kind: ClusterRole | ||
metadata: | ||
name: cluster-autoscaler-role | ||
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: ["batch"] | ||
resources: ["jobs"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["policy"] | ||
resources: ["poddisruptionbudgets"] | ||
verbs: ["watch", "list"] | ||
- apiGroups: ["apps"] | ||
resources: ["daemonsets", "replicasets", "statefulsets"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: ["storage.k8s.io"] | ||
resources: ["storageclasses", "csinodes"] | ||
verbs: ["watch", "list", "get"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
verbs: ["create","list","watch"] | ||
- apiGroups: [""] | ||
resources: ["configmaps"] | ||
resourceNames: ["cluster-autoscaler-status", "cluster-autoscaler-priority-expander"] | ||
verbs: ["delete", "get", "update"] | ||
- apiGroups: ["coordination.k8s.io"] | ||
resources: ["leases"] | ||
verbs: ["watch", "list", "get", "create", "update", "patch", "delete", "deletecollection"] | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: cluster-autoscaler-rolebinding | ||
namespace: kube-system | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-autoscaler-role | ||
subjects: | ||
- kind: ServiceAccount | ||
name: cluster-autoscaler-account | ||
namespace: kube-system | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: cluster-autoscaler-account | ||
namespace: kube-system | ||
|
||
--- | ||
kind: Deployment | ||
apiVersion: apps/v1 | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: cluster-autoscaler | ||
template: | ||
metadata: | ||
namespace: kube-system | ||
labels: | ||
app: cluster-autoscaler | ||
spec: | ||
serviceAccountName: cluster-autoscaler-account | ||
containers: | ||
- name: cluster-autoscaler | ||
image: us.gcr.io/gns-hosting-dev/cluster-autoscaler-amd64:{{ env "TAG" }} | ||
imagePullPolicy: Always | ||
command: | ||
- ./cluster-autoscaler | ||
- --alsologtostderr | ||
- --cloud-config=/config/cloud-config | ||
- --cloud-provider=rancher | ||
- --nodes=$(NODE_ARG) | ||
volumeMounts: | ||
- name: cloud-config | ||
mountPath: /config | ||
readOnly: true | ||
env: | ||
- name: NODE_ARG | ||
valueFrom: | ||
secretKeyRef: | ||
name: cluster-autoscaler-cloud-config | ||
key: autoscaler_node_arg | ||
volumes: | ||
- name: cloud-config | ||
secret: | ||
secretName: cluster-autoscaler-cloud-config |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some information about contacts of maintainers here?
It would be helpful for maintainers to reach out to the cloud provider owners for release coordination when necessary.