2

按照本指南在 AWS 上创建集群自动扩缩器: https ://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/cloudprovider/aws

---
apiVersion: extensions/v1beta1
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
    spec:
      containers:
        - image: gcr.io/google_containers/cluster-autoscaler:v0.6.0
          name: cluster-autoscaler
          resources:
            limits:
              cpu: 100m
              memory: 300Mi
            requests:
              cpu: 100m
              memory: 300Mi
          command:
            - ./cluster-autoscaler
            - --v=4
            - --stderrthreshold=info
            - --cloud-provider=aws
            - --skip-nodes-with-local-storage=false
            - --nodes=2:4:k8s-worker-asg-1
          env:
            - name: AWS_REGION
              value: us-east-1
          volumeMounts:
            - name: ssl-certs
              mountPath: /etc/ssl/certs/ca-certificates.crt
              readOnly: true
          imagePullPolicy: "Always"
      volumes:
        - name: ssl-certs
          hostPath:
            path: "/etc/ssl/certs/ca-certificates.crt"

我已更改k8s-worker-asg-1为我当前的 ASG 名称,该名称由kops. 但是当运行kubectl apply -f deployment.yaml并检查 pods时kubectl get pods -n=kube-system,返回:

NAME                                                                      READY     STATUS             RESTARTS   AGE
cluster-autoscaler-75ccf5b9c9-lhts8                                       0/1       CrashLoopBackOff   6          8m

我试图查看它的日志kubectl logs cluster-autoscaler-75ccf5b9c9-lhts8 -n=kube-system,返回:

failed to open log file "/var/log/pods/8edc3073-dc0b-11e7-a6e5-06361ac15b44/cluster-autoscaler_4.log": open /var/log/pods/8edc3073-dc0b-11e7-a6e5-06361ac15b44/cluster-autoscaler_4.log: no such file or directory

我还尝试描述 pod kubectl describe cluster-autoscaler-75ccf5b9c9-lhts8 -n=kube-system,返回:

the server doesn't have a resource type "cluster-autoscaler-75ccf5b9c9-lhts8"

那么如何调试问题呢?会是什么原因?它需要在 AWS 上存储吗?我还没有在 AWS 上创建任何存储。


顺便说一句,我还有一个问题。如果使用kops在 AWS 上创建 k8s 集群,则更改maxSize,minSize以获取节点大小:

$ kops edit ig nodes
> maxSize: 2
> minSize: 2
$ kops update cluster ${CLUSTER_FULL_NAME} --yes

到目前为止,AWS 上的 Auto Scaling 组已经成为Min:2 Max:4.

是否有必要再次运行此部署? https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler/cloudprovider/aws

kops 不能同时改变 ASG 和 k8s 集群吗?为什么要做另一个步骤来设置cluster-autoscaler命名kube-system空间?

NAME                                                                      READY     STATUS             RESTARTS   AGE
cluster-autoscaler-75ccf5b9c9-lhts8                                       0/1       CrashLoopBackOff   6          8m
4

1 回答 1

0

我已经从 K8s 存储库中尝试过这个官方解决方案。您还需要添加额外的 IAM 策略以访问 AWS Autoscaling 资源。然后,修改https://github.com/kubernetes/kops/tree/master/addons/cluster-autoscaler中的脚本,在您的 K8s 集群上安装 Cluster Autoscaler。请注意,您可能想要更改AWS_REGIONand GROUP_NAME,并且可能MIN_NODESMAX_NODES。我为我工作。

spec:
  api:
    loadBalancer:
      type: Public
  authorization:
    rbac: {}
  additionalPolicies:
    node: |
      [
        {
          "Effect": "Allow",
          "Action": [
            "autoscaling:DescribeAutoScalingGroups",
            "autoscaling:DescribeAutoScalingInstances",
            "autoscaling:SetDesiredCapacity",
            "autoscaling:TerminateInstanceInAutoScalingGroup"
          ],
          "Resource": ["*"]
        }
      ]
于 2018-06-02T08:57:05.487 回答