0

我使用如下所示的命令配置了 HPA

kubectl autoscale deployment isamruntime-v1 --cpu-percent=20 --min=1 --max=3 --namespace=default           
horizontalpodautoscaler.autoscaling/isamruntime-v1 autoscaled

但是,HPA 无法识别 CPU 负载。

pranam@UNKNOWN kubernetes % kubectl get hpa                                                                                 
NAME             REFERENCE                   TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
isamruntime-v1   Deployment/isamruntime-v1   <unknown>/20%   1         3         0          3s

我阅读了许多建议安装指标服务器的文章。所以,我做到了。

pranam@UNKNOWN kubernetes % kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator configured
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader configured
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io configured
serviceaccount/metrics-server configured
deployment.apps/metrics-server configured
service/metrics-server configured
clusterrole.rbac.authorization.k8s.io/system:metrics-server configured
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server configured

我可以看到指标服务器。

pranam@UNKNOWN kubernetes % kubectl get pods -o wide --namespace=kube-system 
NAME                                                  READY   STATUS    RESTARTS   AGE     IP               NODE           NOMINATED NODE   READINESS GATES
calico-kube-controllers-7d88b45844-lz8zw              1/1     Running   0          22d     10.164.27.28     10.164.27.28   <none>           <none>
calico-node-bsx6p                                     1/1     Running   0          8d      10.164.27.39     10.164.27.39   <none>           <none>
calico-node-g229m                                     1/1     Running   0          8d      10.164.27.46     10.164.27.46   <none>           <none>
calico-node-slwrh                                     1/1     Running   0          22d     10.164.27.28     10.164.27.28   <none>           <none>
calico-node-tztjg                                     1/1     Running   0          8d      10.164.27.44     10.164.27.44   <none>           <none>
coredns-7d6bb98ccc-d8nrs                              1/1     Running   0          25d     172.30.93.205    10.164.27.28   <none>           <none>
coredns-7d6bb98ccc-n28dm                              1/1     Running   0          25d     172.30.93.204    10.164.27.28   <none>           <none>
coredns-7d6bb98ccc-zx5jx                              1/1     Running   0          25d     172.30.93.197    10.164.27.28   <none>           <none>
coredns-autoscaler-848db65fc6-lnfvf                   1/1     Running   0          25d     172.30.93.201    10.164.27.28   <none>           <none>
dashboard-metrics-scraper-576c46d9bd-k6z85            1/1     Running   0          25d     172.30.93.195    10.164.27.28   <none>           <none>
ibm-file-plugin-7c57965855-494bz                      1/1     Running   0          22d     172.30.93.216    10.164.27.28   <none>           <none>
ibm-iks-cluster-autoscaler-7df84fb95c-fhtgv           1/1     Running   0          2d23h   172.30.137.98    10.164.27.46   <none>           <none>
ibm-keepalived-watcher-9w4gb                          1/1     Running   0          8d      10.164.27.39     10.164.27.39   <none>           <none>
ibm-keepalived-watcher-ps5zm                          1/1     Running   0          8d      10.164.27.46     10.164.27.46   <none>           <none>
ibm-keepalived-watcher-rzxbs                          1/1     Running   0          8d      10.164.27.44     10.164.27.44   <none>           <none>
ibm-keepalived-watcher-w6mxb                          1/1     Running   0          25d     10.164.27.28     10.164.27.28   <none>           <none>
ibm-master-proxy-static-10.164.27.28                  2/2     Running   0          25d     10.164.27.28     10.164.27.28   <none>           <none>
ibm-master-proxy-static-10.164.27.39                  2/2     Running   0          8d      10.164.27.39     10.164.27.39   <none>           <none>
ibm-master-proxy-static-10.164.27.44                  2/2     Running   0          8d      10.164.27.44     10.164.27.44   <none>           <none>
ibm-master-proxy-static-10.164.27.46                  2/2     Running   0          8d      10.164.27.46     10.164.27.46   <none>           <none>
ibm-storage-watcher-67466b969f-ps55m                  1/1     Running   0          22d     172.30.93.217    10.164.27.28   <none>           <none>
kubernetes-dashboard-c6b4b9d77-27zwb                  1/1     Running   2          22d     172.30.93.218    10.164.27.28   <none>           <none>
metrics-server-79d847cf58-6frsf                       2/2     Running   0          3m23s   172.30.93.226    10.164.27.28   <none>           <none>
public-crbro6um6l04jalpqrsl5g-alb1-8465f75bb4-88vl5   4/4     Running   0          11h     172.30.93.225    10.164.27.28   <none>           <none>
public-crbro6um6l04jalpqrsl5g-alb1-8465f75bb4-vx68d   4/4     Running   0          11h     172.30.137.104   10.164.27.46   <none>           <none>
vpn-58b48cdc7c-4lp9c                                  1/1     Running   0          25d     172.30.93.193    10.164.27.28   <none>           <none>

我正在使用 Istio 和 sysdig。不确定这是否会破坏任何东西。我的 k8s 版本如下所示。

pranam@UNKNOWN kubernetes % kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.7", GitCommit:"be3d344ed06bff7a4fc60656200a93c74f31f9a4", GitTreeState:"clean", BuildDate:"2020-02-11T19:34:02Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.7+IKS", GitCommit:"3305158dfe9ee1f89f596ef260135dcba881848c", GitTreeState:"clean", BuildDate:"2020-06-17T18:32:22Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

我的 YAML 文件是

#Assumes create-docker-store-secret.sh used to create dockerlogin secret
#Assumes create-secrets.sh used to create key file, sam admin, and cfgsvc secrets
apiVersion: storage.k8s.io/v1beta1
# Create StorageClass with gidallocate=true to allow non-root user access to mount
# This is used by PostgreSQL container
kind: StorageClass
metadata:
   name: ibmc-file-bronze-gid
   labels:
     kubernetes.io/cluster-service: "true"
provisioner: ibm.io/ibmc-file
parameters:
   type: "Endurance"
   iopsPerGB: "2"
   sizeRange: "[1-12000]Gi"
   mountOptions: nfsvers=4.1,hard
   billingType: "hourly"
   reclaimPolicy: "Delete"
   classVersion: "2"
   gidAllocate: "true"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ldaplib
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50M
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ldapslapd
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50M
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ldapsecauthority
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50M
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgresqldata
spec:
  storageClassName: ibmc-file-bronze-gid
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50M
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: isamconfig
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50M
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: openldap
  labels:
    app: openldap
spec:
  selector:
    matchLabels:
      app: openldap
  replicas: 1
  template:
    metadata:
      labels:
        app: openldap
    spec:
      volumes:
        - name: ldaplib
          persistentVolumeClaim:
            claimName: ldaplib
        - name: ldapslapd
          persistentVolumeClaim:
            claimName: ldapslapd
        - name: ldapsecauthority
          persistentVolumeClaim:
            claimName: ldapsecauthority
        - name: openldap-keys
          secret:
            secretName: openldap-keys
      containers:
        - name: openldap
          image: ibmcom/isam-openldap:9.0.7.0
          ports:
            - containerPort: 636
          env:
            - name: LDAP_DOMAIN
              value: ibm.com
            - name: LDAP_ADMIN_PASSWORD
              value: Passw0rd
            - name: LDAP_CONFIG_PASSWORD
              value: Passw0rd
          volumeMounts:
            - mountPath: /var/lib/ldap
              name: ldaplib
            - mountPath: /etc/ldap/slapd.d
              name: ldapslapd
            - mountPath: /var/lib/ldap.secAuthority
              name: ldapsecauthority
            - mountPath: /container/service/slapd/assets/certs
              name: openldap-keys
# This line is needed when running on Kubernetes 1.9.4 or above
          args: [ "--copy-service"]

# useful for debugging startup issues - can run bash, then exec to the container and poke around
#          command: [ "/bin/bash"]
#          args: [ "-c", "while /bin/true ; do sleep 5; done" ]
# Just this line to get debug output from openldap startup
#          args: [ "--loglevel" , "trace","--copy-service"]
---
# for external service access, see https://console.bluemix.net/docs/containers/cs_apps.html#cs_apps_public_nodeport
apiVersion: v1
kind: Service
metadata:
  name: openldap
  labels:
    app: openldap
spec:
  ports:
    - port: 636
      name: ldaps
      protocol: TCP
  selector:
    app: openldap
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgresql
  labels:
    app: postgresql
spec:
  selector:
    matchLabels:
      app: postgresql
  replicas: 1
  template:
    metadata:
      labels:
        app: postgresql
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 70
        fsGroup: 0
      volumes:
        - name: postgresqldata
          persistentVolumeClaim:
            claimName: postgresqldata
        - name: postgresql-keys
          secret:
            secretName: postgresql-keys
      containers:
        - name: postgresql
          image: ibmcom/isam-postgresql:9.0.7.0
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_USER
              value: postgres
            - name: POSTGRES_PASSWORD
              value: Passw0rd
            - name: POSTGRES_DB
              value: isam
            - name: POSTGRES_SSL_KEYDB
              value: /var/local/server.pem
            - name: PGDATA
              value: /var/lib/postgresql/data/db-files/
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgresqldata
            - mountPath: /var/local
              name: postgresql-keys
# useful for debugging startup issues - can run bash, then exec to the container and poke around
#          command: [ "/bin/bash"]
#          args: [ "-c", "while /bin/true ; do sleep 5; done" ]
---
# for external service access, see https://console.bluemix.net/docs/containers/cs_apps.html#cs_apps_public_nodeport
apiVersion: v1
kind: Service
metadata:
  name: postgresql
spec:
  ports:
    - port: 5432
      name: postgresql
      protocol: TCP
  selector:
    app: postgresql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: isamconfig
  labels:
    app: isamconfig
spec:
  selector:
    matchLabels:
      app: isamconfig
  replicas: 1
  template:
    metadata:
      labels:
        app: isamconfig
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser:    6000
      volumes:
        - name: isamconfig
          persistentVolumeClaim:
            claimName: isamconfig
        - name: isamconfig-logs
          emptyDir: {}
      containers:
        - name: isamconfig
          image: ibmcom/isam:9.0.7.1_IF4
          volumeMounts:
            - mountPath: /var/shared
              name: isamconfig
            - mountPath: /var/application.logs
              name: isamconfig-logs
          env:
            - name: SERVICE
              value: config
            - name: CONTAINER_TIMEZONE
              value: Europe/London
            - name: ADMIN_PWD
              valueFrom:
                secretKeyRef:
                  name: samadmin
                  key: adminpw
          readinessProbe:
            tcpSocket:
              port:  9443
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            tcpSocket:
              port: 9443
            initialDelaySeconds: 120
            periodSeconds: 20
#          command: [ "/sbin/bootstrap.sh" ]
      imagePullSecrets:
        - name: dockerlogin
---
# for external service access, see https://console.bluemix.net/docs/containers/cs_apps.html#cs_apps_public_nodeport
apiVersion: v1
kind: Service
metadata:
  name: isamconfig
spec:
# To make the LMI internet facing, make it a NodePort
  type: NodePort
  ports:
    - port: 9443
      name: isamconfig
      protocol: TCP
# make this one statically allocated
      nodePort: 30442
  selector:
    app: isamconfig
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: isamwrprp1-v1
  labels:
    app: isamwrprp1
spec:
  selector:
    matchLabels:
      app: isamwrprp1
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: isamwrprp1
        version: v1
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser:    6000
      volumes:
        - name: isamconfig
          emptyDir: {}
        - name: isamwrprp1-logs
          emptyDir: {}
      containers:
        - name: isamwrprp1
          image: ibmcom/isam:9.0.7.1_IF4
          ports:
            - containerPort: 443
          volumeMounts:
            - mountPath: /var/shared
              name: isamconfig
            - mountPath: /var/application.logs
              name: isamwrprp1-logs
          env:
            - name: SERVICE
              value: webseal
            - name: INSTANCE
              value: rp1
            - name: CONTAINER_TIMEZONE
              value: Europe/London
            - name: AUTO_RELOAD_FREQUENCY
              value: "5"
            - name: CONFIG_SERVICE_URL
              value: https://isamconfig:9443/shared_volume
            - name: CONFIG_SERVICE_USER_NAME
              value: cfgsvc
            - name: CONFIG_SERVICE_USER_PWD
              valueFrom:
                secretKeyRef:
                  name: configreader
                  key: cfgsvcpw
          livenessProbe:
            exec:
              command:
              - /sbin/health_check.sh
              - livenessProbe
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
          readinessProbe:
            exec:
              command:
              - /sbin/health_check.sh
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
      imagePullSecrets:
        - name: dockerlogin
---
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: isamwrprp1-v2
  labels:
    app: isamwrprp1
spec:
  selector:
    matchLabels:
      app: isamwrprp1
      version: v2
  replicas: 1
  template:
    metadata:
      labels:
        app: isamwrprp1
        version: v2
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser:    6000
      volumes:
        - name: isamconfig
          emptyDir: {}
        - name: isamwrprp1-logs
          emptyDir: {}
      containers:
        - name: isamwrprp1
          image: ibmcom/isam:9.0.7.1_IF4
          ports:
            - containerPort: 443
          volumeMounts:
            - mountPath: /var/shared
              name: isamconfig
            - mountPath: /var/application.logs
              name: isamwrprp1-logs
          env:
            - name: SERVICE
              value: webseal
            - name: INSTANCE
              value: rp1
            - name: CONTAINER_TIMEZONE
              value: Europe/London
            - name: AUTO_RELOAD_FREQUENCY
              value: "5"
            - name: CONFIG_SERVICE_URL
              value: https://isamconfig:9443/shared_volume
            - name: CONFIG_SERVICE_USER_NAME
              value: cfgsvc
            - name: CONFIG_SERVICE_USER_PWD
              valueFrom:
                secretKeyRef:
                  name: configreader
                  key: cfgsvcpw
          livenessProbe:
            exec:
              command:
              - /sbin/health_check.sh
              - livenessProbe
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
          readinessProbe:
            exec:
              command:
              - /sbin/health_check.sh
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
      imagePullSecrets:
        - name: dockerlogin
---
# for external service access, see https://console.bluemix.net/docs/containers/cs_apps.html#cs_apps_public_nodeport
apiVersion: v1
kind: Service
metadata:
  name: isamwrprp1
spec:
  type: NodePort
  sessionAffinity: ClientIP
  ports:
    - port: 443
      name: isamwrprp1
      protocol: TCP
      nodePort: 30443
  selector:
    app: isamwrprp1
---
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: isamwrpmobile
  labels:
    app: isamwrpmobile
spec:
  selector:
    matchLabels:
      app: isamwrpmobile
  replicas: 1
  template:
    metadata:
      labels:
        app: isamwrpmobile
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser:    6000
      volumes:
        - name: isamconfig
          emptyDir: {}
        - name: isamwrpmobile-logs
          emptyDir: {}
      containers:
        - name: isamwrpmobile
          image: ibmcom/isam:9.0.7.1_IF4
          ports:
            - containerPort: 443
          volumeMounts:
            - mountPath: /var/shared
              name: isamconfig
            - mountPath: /var/application.logs
              name: isamwrpmobile-logs
          env:
            - name: SERVICE
              value: webseal
            - name: INSTANCE
              value: mobile
            - name: CONTAINER_TIMEZONE
              value: Europe/London
            - name: AUTO_RELOAD_FREQUENCY
              value: "5"
            - name: CONFIG_SERVICE_URL
              value: https://isamconfig:9443/shared_volume
            - name: CONFIG_SERVICE_USER_NAME
              value: cfgsvc
            - name: CONFIG_SERVICE_USER_PWD
              valueFrom:
                secretKeyRef:
                  name: configreader
                  key: cfgsvcpw
          livenessProbe:
            exec:
              command:
              - /sbin/health_check.sh
              - livenessProbe
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
          readinessProbe:
            exec:
              command:
              - /sbin/health_check.sh
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
      imagePullSecrets:
        - name: dockerlogin
---
# for external service access, see https://console.bluemix.net/docs/containers/cs_apps.html#cs_apps_public_nodeport
apiVersion: v1
kind: Service
metadata:
  name: isamwrpmobile
spec:
  type: NodePort
  sessionAffinity: ClientIP
  ports:
    - port: 443
      name: isamwrpmobile
      protocol: TCP
      nodePort: 30444
  selector:
    app: isamwrpmobile
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: isamruntime-v1
  labels:
    app: isamruntime
spec:
  selector:
    matchLabels:
      app: isamruntime
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: isamruntime
        version: v1
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser:    6000
      volumes:
        - name: isamconfig
          emptyDir: {}
        - name: isamruntime-logs
          emptyDir: {}
      containers:
        - name: isamruntime
          image: ibmcom/isam:9.0.7.1_IF4
          ports:
            - containerPort: 443
          volumeMounts:
            - mountPath: /var/shared
              name: isamconfig
            - mountPath: /var/application.logs
              name: isamruntime-logs
          env:
            - name: SERVICE
              value: runtime
            - name: CONTAINER_TIMEZONE
              value: Europe/London
            - name: AUTO_RELOAD_FREQUENCY
              value: "5"
            - name: CONFIG_SERVICE_URL
              value: https://isamconfig:9443/shared_volume
            - name: CONFIG_SERVICE_USER_NAME
              value: cfgsvc
            - name: CONFIG_SERVICE_USER_PWD
              valueFrom:
                secretKeyRef:
                  name: configreader
                  key: cfgsvcpw
          livenessProbe:
            exec:
              command:
              - /sbin/health_check.sh
              - livenessProbe
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
          readinessProbe:
            exec:
              command:
              - /sbin/health_check.sh
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
      imagePullSecrets:
        - name: dockerlogin
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: isamruntime-v2
  labels:
    app: isamruntime
spec:
  selector:
    matchLabels:
      app: isamruntime
      version: v2
  replicas: 1
  template:
    metadata:
      labels:
        app: isamruntime
        version: v2
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser:    6000
      volumes:
        - name: isamconfig
          emptyDir: {}
        - name: isamruntime-logs
          emptyDir: {}
      containers:
        - name: isamruntime
          image: ibmcom/isam:9.0.7.1_IF4
          ports:
            - containerPort: 443
          volumeMounts:
            - mountPath: /var/shared
              name: isamconfig
            - mountPath: /var/application.logs
              name: isamruntime-logs
          env:
            - name: SERVICE
              value: runtime
            - name: CONTAINER_TIMEZONE
              value: Europe/London
            - name: AUTO_RELOAD_FREQUENCY
              value: "5"
            - name: CONFIG_SERVICE_URL
              value: https://isamconfig:9443/shared_volume
            - name: CONFIG_SERVICE_USER_NAME
              value: cfgsvc
            - name: CONFIG_SERVICE_USER_PWD
              valueFrom:
                secretKeyRef:
                  name: configreader
                  key: cfgsvcpw
          livenessProbe:
            exec:
              command:
              - /sbin/health_check.sh
              - livenessProbe
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
          readinessProbe:
            exec:
              command:
              - /sbin/health_check.sh
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
      imagePullSecrets:
        - name: dockerlogin
---
apiVersion: v1
kind: Service
metadata:
  name: isamruntime
spec:
  ports:
    - port: 443
      name: isamruntime
      protocol: TCP
  selector:
    app: isamruntime
---

我不确定为什么 CPU 负载显示为未知。我是否错过了一步或犯了任何错误?有人可以帮忙吗?

问候普拉南

4

2 回答 2

1

根据显示的问题,您似乎没有在 delployment.yaml 文件中设置资源限制。

如果你去执行,kubectl explain deployment那么你会在容器规格中看到 -

resources:
   limits:
      cpu:
      memory:
   requests:
      cpu:
      memory:

如果您向上述键添加值,那么 hpa 问题肯定会得到解决

于 2020-07-17T10:53:31.203 回答
0

resources您在定义应用程序的部署时是否指定了块?我不记得它是在哪里说的,但是当我忘记它时,我遇到过这种情况。

有关管理容器资源的更多信息:https ://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

于 2020-07-17T10:34:54.917 回答