如何在AWS上通过kops安装的k8s集群自动扩展器?

时间:2017-12-08 12:00:57

标签: amazon-web-services kubernetes cluster-computing autoscaling kops

按照本指南在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更改为我kops创建的当前ASG名称。 但是,当运行kubectl apply -f deployment.yaml并检查窗格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群集,则针对节点大小更改maxSizeminSize

$ 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

1 个答案:

答案 0 :(得分:0)

我在K8s资料库中尝试过这个官方解决方案。您还需要添加其他IAM策略以访问AWS Autoscaling资源。 然后,修改https://github.com/kubernetes/kops/tree/master/addons/cluster-autoscaler中的脚本以在K8s群集上安装Cluster Autoscaler。请注意,您可能希望更改AWS_REGIONGROUP_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": ["*"]
        }
      ]
相关问题