-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tencentcloud to list of supported cloud providers
- Loading branch information
Showing
63 changed files
with
78,162 additions
and
2 deletions.
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
43 changes: 43 additions & 0 deletions
43
cluster-autoscaler/cloudprovider/builder/builder_tencentcloud.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,43 @@ | ||
//go:build tencentcloud | ||
// +build tencentcloud | ||
|
||
/* | ||
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/tencentcloud" | ||
"k8s.io/autoscaler/cluster-autoscaler/config" | ||
) | ||
|
||
// AvailableCloudProviders supported by the cloud provider builder. | ||
var AvailableCloudProviders = []string{ | ||
cloudprovider.TencentcloudProviderName, | ||
} | ||
|
||
// DefaultCloudProvider is TKE. | ||
const DefaultCloudProvider = cloudprovider.TkeProviderName | ||
|
||
func buildCloudProvider(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider { | ||
switch opts.CloudProviderName { | ||
case cloudprovider.TencentcloudProviderName: | ||
return tencentcloud.BuildTencentcloud(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,4 @@ | ||
approvers: | ||
# - alphajc | ||
reviewers: | ||
# - alphajc |
181 changes: 181 additions & 0 deletions
181
cluster-autoscaler/cloudprovider/tencentcloud/README.md
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,181 @@ | ||
# Cluster Autoscaler on TencentCloud | ||
|
||
On TencentCloud, Cluster Autoscaler utilizes CVM Auto Scaling Groups to manage node | ||
groups. Cluster Autoscaler typically runs as a `Deployment` in your cluster. | ||
|
||
## Requirements | ||
|
||
Cluster Autoscaler requires [TKE](https://intl.cloud.tencent.com/document/product/457) v1.10.x or greater. | ||
|
||
## Permissions | ||
|
||
### CAM Policy | ||
|
||
The following policy provides the minimum privileges necessary for Cluster Autoscaler to run: | ||
|
||
```json | ||
{ | ||
"version": "2.0", | ||
"statement": [ | ||
{ | ||
"effect": "allow", | ||
"action": [ | ||
"tke:DeleteClusterInstances", | ||
"tke:DescribeClusterAsGroups", | ||
"as:ModifyAutoScalingGroup", | ||
"as:RemoveInstances", | ||
"as:StopAutoScalingInstances", | ||
"as:DescribeAutoScalingGroups", | ||
"as:DescribeAutoScalingInstances", | ||
"as:DescribeLaunchConfigurations", | ||
"as:DescribeAutoScalingActivities" | ||
], | ||
"resource": [ | ||
"*" | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### Using TencentCloud Credentials | ||
|
||
> NOTICE: Make sure the [access key](https://intl.cloud.tencent.com/document/product/598/32675) you will be using has all the above permissions | ||
|
||
```yaml | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: tencentcloud-secret | ||
type: Opaque | ||
data: | ||
tencentcloud_secret_id: BASE64_OF_YOUR_TENCENTCLOUD_SECRET_ID | ||
tencentcloud_secret_key: BASE64_OF_YOUR_TENCENTCLOUD_SECRET_KEY | ||
``` | ||
Please refer to the [relevant Kubernetes | ||
documentation](https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-manually) | ||
for creating a secret manually. | ||
```yaml | ||
env: | ||
- name: SECRET_ID | ||
valueFrom: | ||
secretKeyRef: | ||
name: tencentcloud-secret | ||
key: tencentcloud_secret_id | ||
- name: SECRET_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: tencentcloud-secret | ||
key: tencentcloud_secret_key | ||
- name: REGION | ||
value: YOUR_TENCENCLOUD_REGION | ||
- name: REGION_NAME | ||
value: YOUR_TENCENCLOUD_REGION_NAME | ||
- name: CLUSTER_ID | ||
value: YOUR_TKE_CLUSTER_ID | ||
``` | ||
## Setup | ||
### cluster-autoscaler deployment | ||
```yaml | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: cluster-autoscaler | ||
namespace: kube-system | ||
spec: | ||
selector: | ||
matchLabels: | ||
qcloud-app: cluster-autoscaler | ||
template: | ||
metadata: | ||
labels: | ||
qcloud-app: cluster-autoscaler | ||
spec: | ||
containers: | ||
- args: | ||
- --cloud-provider=tencentcloud | ||
- --v=4 | ||
- --ok-total-unready-count=3 | ||
- --cloud-config=/etc/kubernetes/qcloud.conf | ||
- --scale-down-utilization-threshold=0.8 | ||
- --scale-down-enabled=true | ||
- --max-total-unready-percentage=33 | ||
- --nodes=[min]:[max]:[ASG_ID] | ||
- --logtostderr | ||
- --kubeconfig=/kubeconfig/config | ||
command: | ||
- /cluster-autoscaler | ||
env: | ||
- name: SECRET_ID | ||
valueFrom: | ||
secretKeyRef: | ||
name: tencentcloud-secret | ||
key: tencentcloud_secret_id | ||
- name: SECRET_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: tencentcloud-secret | ||
key: tencentcloud_secret_key | ||
- name: REGION | ||
value: YOUR_TENCENCLOUD_REGION | ||
- name: REGION_NAME | ||
value: YOUR_TENCENCLOUD_REGION_NAME | ||
- name: CLUSTER_ID | ||
value: YOUR_TKE_CLUSTER_ID | ||
image: ccr.ccs.tencentyun.com/tkeimages/cluster-autoscaler:v1.18.4-49692187a | ||
imagePullPolicy: Always | ||
name: cluster-autoscaler | ||
resources: | ||
limits: | ||
cpu: "1" | ||
memory: 1Gi | ||
requests: | ||
cpu: 250m | ||
memory: 256Mi | ||
volumeMounts: | ||
- mountPath: /etc/localtime | ||
name: tz-config | ||
hostAliases: | ||
- hostnames: | ||
- cbs.api.qcloud.com | ||
- cvm.api.qcloud.com | ||
- lb.api.qcloud.com | ||
- tag.api.qcloud.com | ||
- snapshot.api.qcloud.com | ||
- monitor.api.qcloud.com | ||
- scaling.api.qcloud.com | ||
- ccs.api.qcloud.com | ||
ip: 169.254.0.28 | ||
- hostnames: | ||
- tke.internal.tencentcloudapi.com | ||
- clb.internal.tencentcloudapi.com | ||
- cvm.internal.tencentcloudapi.com | ||
- tag.internal.tencentcloudapi.com | ||
- as.tencentcloudapi.com | ||
- cbs.tencentcloudapi.com | ||
- cvm.tencentcloudapi.com | ||
- vpc.tencentcloudapi.com | ||
- tke.tencentcloudapi.com | ||
ip: 169.254.0.95 | ||
restartPolicy: Always | ||
serviceAccount: kube-admin | ||
serviceAccountName: kube-admin | ||
tolerations: | ||
- effect: NoSchedule | ||
key: node-role.kubernetes.io/master | ||
volumes: | ||
- hostPath: | ||
path: /etc/localtime | ||
type: "" | ||
name: tz-config | ||
``` | ||
### Auto-Discovery Setup | ||
Auto Discovery is not supported in TencentCloud currently. |
66 changes: 66 additions & 0 deletions
66
cluster-autoscaler/cloudprovider/tencentcloud/metrics/metrics.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,66 @@ | ||
/* | ||
Copyright 2016 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 metrics | ||
|
||
import ( | ||
tencent_errors "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | ||
k8smetrics "k8s.io/component-base/metrics" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
) | ||
|
||
const ( | ||
caNamespace = "cluster_autoscaler" | ||
) | ||
|
||
var ( | ||
cloudAPIInvokedCount = k8smetrics.NewCounterVec( | ||
&k8smetrics.CounterOpts{ | ||
Namespace: caNamespace, | ||
Name: "invoked_cloudapi_total", | ||
Help: "Number of cloudapi invoked by Node Autoprovisioning.", | ||
}, []string{"service", "ops"}, | ||
) | ||
|
||
cloudAPIInvokedErrorCount = k8smetrics.NewCounterVec( | ||
&k8smetrics.CounterOpts{ | ||
Namespace: caNamespace, | ||
Name: "invoked_cloudapi_error_total", | ||
Help: "Number of errors that cloudapi invoked by Node Autoprovisioning.", | ||
}, []string{"service", "ops", "code"}, | ||
) | ||
) | ||
|
||
func init() { | ||
legacyregistry.MustRegister(cloudAPIInvokedCount) | ||
legacyregistry.MustRegister(cloudAPIInvokedErrorCount) | ||
} | ||
|
||
// RegisterCloudAPIInvoked registers cloudapi invoked | ||
func RegisterCloudAPIInvoked(service string, ops string, err error) { | ||
cloudAPIInvokedCount.WithLabelValues(service, ops).Inc() | ||
|
||
if err != nil { | ||
if e, ok := err.(*tencent_errors.TencentCloudSDKError); ok { | ||
RegisterCloudAPIInvokedError("as", "DescribeAutoScalingGroups", e.Code) | ||
} | ||
} | ||
} | ||
|
||
// RegisterCloudAPIInvokedError registers error in cloudapi invoked | ||
func RegisterCloudAPIInvokedError(service string, ops string, code string) { | ||
cloudAPIInvokedErrorCount.WithLabelValues(service, ops, code).Inc() | ||
} |
Oops, something went wrong.