Skip to content

Commit

Permalink
Add tencentcloud to list of supported cloud providers
Browse files Browse the repository at this point in the history
  • Loading branch information
alphajc committed Feb 22, 2022
1 parent 5cf3b96 commit de0588d
Show file tree
Hide file tree
Showing 63 changed files with 78,162 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cluster-autoscaler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ You should also take a look at the notes and "gotchas" for your specific cloud p
* [ClusterAPI](./cloudprovider/clusterapi/README.md)
* [BizflyCloud](./cloudprovider/bizflycloud/README.md)
* [Vultr](./cloudprovider/vultr/README.md)
* [TencentCloud](./cloudprovider/tencentcloud/README.md)

# Releases

Expand Down Expand Up @@ -171,3 +172,4 @@ Supported cloud providers:
* Hetzner https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/hetzner/README.md
* Cluster API https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/clusterapi/README.md
* Vultr https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/vultr/README.md
* TencentCloud https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/tencentcloud/README.md
8 changes: 6 additions & 2 deletions cluster-autoscaler/cloudprovider/builder/builder_all.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !gce && !aws && !azure && !kubemark && !alicloud && !magnum && !digitalocean && !clusterapi && !huaweicloud && !ionoscloud && !linode && !hetzner && !bizflycloud && !brightbox && !packet && !oci && !vultr
// +build !gce,!aws,!azure,!kubemark,!alicloud,!magnum,!digitalocean,!clusterapi,!huaweicloud,!ionoscloud,!linode,!hetzner,!bizflycloud,!brightbox,!packet,!oci,!vultr
//go:build !gce && !aws && !azure && !kubemark && !alicloud && !magnum && !digitalocean && !clusterapi && !huaweicloud && !ionoscloud && !linode && !hetzner && !bizflycloud && !brightbox && !packet && !oci && !vultr && !tencentcloud
// +build !gce,!aws,!azure,!kubemark,!alicloud,!magnum,!digitalocean,!clusterapi,!huaweicloud,!ionoscloud,!linode,!hetzner,!bizflycloud,!brightbox,!packet,!oci,!vultr,!tencentcloud

/*
Copyright 2018 The Kubernetes Authors.
Expand Down Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/ovhcloud"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/packet"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/tencentcloud"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/vultr"
"k8s.io/autoscaler/cluster-autoscaler/config"
)
Expand All @@ -66,6 +67,7 @@ var AvailableCloudProviders = []string{
cloudprovider.BrightboxProviderName,
cloudprovider.PacketProviderName,
cloudprovider.VultrProviderName,
cloudprovider.TencentcloudProviderName,
}

// DefaultCloudProvider is GCE.
Expand Down Expand Up @@ -113,6 +115,8 @@ func buildCloudProvider(opts config.AutoscalingOptions, do cloudprovider.NodeGro
return oci.BuildOCI(opts, do, rl)
case cloudprovider.VultrProviderName:
return vultr.BuildVultr(opts, do, rl)
case cloudprovider.TencentcloudProviderName:
return tencentcloud.BuildTencentcloud(opts, do, rl)
}
return nil
}
43 changes: 43 additions & 0 deletions cluster-autoscaler/cloudprovider/builder/builder_tencentcloud.go
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
}
2 changes: 2 additions & 0 deletions cluster-autoscaler/cloudprovider/cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const (
VultrProviderName = "vultr"
// PacketProviderName gets the provider name of packet
PacketProviderName = "packet"
// TencentcloudProviderName gets the provider name of tencentcloud
TencentcloudProviderName = "tencentcloud"
)

// CloudProvider contains configuration info and functions for interacting with
Expand Down
4 changes: 4 additions & 0 deletions cluster-autoscaler/cloudprovider/tencentcloud/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
approvers:
# - alphajc
reviewers:
# - alphajc
181 changes: 181 additions & 0 deletions cluster-autoscaler/cloudprovider/tencentcloud/README.md
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 cluster-autoscaler/cloudprovider/tencentcloud/metrics/metrics.go
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()
}
Loading

0 comments on commit de0588d

Please sign in to comment.