华为云用户手册

  • 符合策略实例的资源定义 示例capabilities中的各项参数符合策略实例。 apiVersion: v1 kind: Pod metadata: name: opa-allowed labels: owner: me.agilebank.demo spec: containers: - name: opa image: openpolicyagent/opa:0.9.2 args: - "run" - "--server" - "--addr=localhost:8080" securityContext: capabilities: add: ["something"] drop: ["must_drop", "another_one"] resources: limits: cpu: "100m" memory: "30Mi"
  • ConfigMap资源文件配置说明 ConfigMap资源文件支持json和yaml两种文件格式,且文件大小不得超过2MB。 json文件格式 文件名称为configmap.json,配置示例如下: { "kind": "ConfigMap", "apiVersion": "v1", "metadata": { "name": "paas-broker-app-017", "namespace": "test" }, "data": { "context": "{\"applicationComponent\":{\"properties\":{\"custom_spec\":{}},\"node_name\":\"paas-broker-app\",\"stack_id\":\"0177eae1-89d3-cb8a-1f94-c0feb7e91d7b\"},\"softwareComponents\":[{\"properties\":{\"custom_spec\":{}},\"node_name\":\"paas-broker\",\"stack_id\":\"0177eae1-89d3-cb8a-1f94-c0feb7e91d7b\"}]}" } } yaml文件格式 文件名称为configmap.yaml,配置示例如下: apiVersion: v1 kind: ConfigMap metadata: name: test-configmap namespace: default data: data-1: "value-1" data-2: "value-2"
  • 相关操作 通过集群控制台,您还可以执行表2中的操作。 表2 相关操作 操作 说明 查看详情 单击配置项名称即可查看配置项数据详情。 编辑YAML 单击配置项名称后的“编辑YAML”,可查看并编辑当前配置项的YAML文件。 更新 单击配置项名称后的“更新”。 根据表1更改信息。 单击“确定”提交已修改的信息。 删除 单击配置项名称后的“删除”,并单击“是”进行确认。 批量删除 勾选需要删除的配置项。 单击左上角的“批量删除”。 单击“是”进行确认。
  • 创建配置项 登录集群控制台,单击左侧导航栏的“配置项与密钥”,选择“配置项”页签。您还可以直接创建配置项或基于YAML来创建,若希望通过YAML创建,请跳转至4。 选择需要创建配置项的命名空间。 直接创建配置项。单击“创建配置项”。 参照表1设置新增配置参数。 表1 新建配置参数说明 参数 参数说明 名称 新建的配置项名称,同一个命名空间里命名必须唯一。 命名空间 新建配置项所在的命名空间,默认为当前查看的命名空间。 描述 配置项的描述信息。 配置项数据 工作负载配置的数据可以在容器中使用,或被用来存储配置数据。 单击 ,输入键、值。其中,“键”代表配置名;“值”代表配置内容。 配置标签 标签以Key/value键值对的形式附加到各种对象上(如工作负载、节点、服务等)。 标签定义了这些对象的可识别属性,用来对它们进行管理和选择。 输入标签键、值。 单击“添加” 。 基于YAML创建配置项。在创建配置项页面右侧单击“YAML创建”。 若需要通过上传文件的方式创建资源,请确保资源描述文件已创建。支持json或yaml格式,详细请参见ConfigMap资源文件配置说明。 您可以导入或直接编写文件内容,格式为YAML或JSON。 方式一:导入编排文件。 单击“导入”,导入格式为YAML或JSON的文件。编排内容中可直接展示YAML或JSON文件的内容。 方式二:直接编排内容。 在编排内容区域框中,输入YAML或JSON文件内容。 配置完成后,单击“确定”。 配置项列表中会出现新创建的配置项。
  • 策略实例示例 以下策略实例展示了策略定义生效的资源类型,parameters中的allowedFlexVolumes字段定义了允许的driver类型列表。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sPSPFlexVolumes metadata: name: psp-flexvolume-drivers spec: match: kinds: - apiGroups: [""] kinds: ["Pod"] parameters: allowedFlexVolumes: #[] - driver: "example/lvm" - driver: "example/cifs"
  • 符合策略实例的资源定义 示例中flexVolume中的类型均在上述定义的允许范围内,符合策略实例。 apiVersion: v1 kind: Pod metadata: name: nginx-flexvolume-driver-allowed labels: app: nginx-flexvolume-driver spec: containers: - name: nginx image: nginx volumeMounts: - mountPath: /test name: test-volume readOnly: true volumes: - name: test-volume flexVolume: driver: "example/lvm"
  • 不符合策略实例的资源定义 示例中flexVolume中的类型不在上述定义的允许范围内,不符合策略实例。 apiVersion: v1 kind: Pod metadata: name: nginx-flexvolume-driver-disallowed labels: app: nginx-flexvolume-driver spec: containers: - name: nginx image: nginx volumeMounts: - mountPath: /test name: test-volume readOnly: true volumes: - name: test-volume flexVolume: driver: "example/testdriver" #"example/lvm"
  • 概览 单击节点名称,可以进入节点概览页,在这里,您可以方便地查看资源概况,包括节点状态、Pod数量以及异常事件。此外,还可以浏览近一小时的监控概览,其中包括CPU使用率、内存使用率和网络流入/流出速率这些常见的监控指标。 图2 资源概况和监控概览 同时,概览页面还提供了Pod使用趋势功能,您可以从中了解节点中各Top5的Pod的CPU使用率、CPU使用量、内存使用率和内存使用量(在图表左上角切换对应指标),并且支持查看降序Top5和升序Top5数据(在图表右上角进行切换)。 图3 Pod使用趋势 如需了解更多指标,请前往监控页面查看。
  • 节点列表 节点列表中包含节点名称、状态、IP地址、容器组(已分配/总额度)、CPU申请比率/限制比率/使用率,以及内存申请比率/限制比率/使用率等信息。 图1 节点列表 您可以通过在列表上方按照节点名称、状态、私有地址和公网地址进行筛选,快速找到需要的节点。在列表的右上角,您可以单击按钮来导出全部节点数据,或者选择部分节点进行导出,此时仅导出所选中的数据。导出的文件为“.xlsx”格式,文件命名中包含时间戳。 当节点的CPU限制比率或内存限制比率超过100%时,意味着节点资源超分,节点上的负载限制值(可使用的最大值)之和已经超过了节点规格。如果负载占用资源过高,可能会导致节点异常。
  • Pod列表 Pod列表中包含了实例名称、状态、命名空间、实例IP、所在节点、重启次数、CPU申请/限制、内存申请/限制,以及CPU和内存使用率等详细信息。 图4 Pod列表 您可以通过在列表上方按照实例名称、状态、命名空间、实例IP和所在节点进行筛选,快速找到需要的实例。在列表的右上角,您可以单击按钮来导出全部实例数据,或者选择部分实例进行导出,此时仅导出所选中的数据。导出的文件为“.xlsx”格式,文件命名中包含时间戳。 单击实例名称可以查看实例的详细监控数据。更多相关内容,请参见Pod。
  • 监控 在此处,您可以方便地查看节点在近1小时、近8小时、近24小时以及自定义时间段内各维度资源的使用情况。如需查看更多监控信息,请单击“查看全部仪表盘”,跳转至“仪表盘”页面,相应指导请参见仪表盘。 CPU 单位时间内节点CPU使用情况。 图5 CPU 内存 单位时间内节点内存使用情况。 图6 内存 网络 节点上的容器网络流量,用于监控节点上的容器网络负载情况。 图7 网络 节点平均负载 节点的平均负载是指在一定时间内,节点上正在运行的进程数量的平均值,用来评估节点上正在运行的进程数量是否过多,是否超出了节点的处理能力。通常情况下,节点平均负载应该保持在一个合理的范围内,以确保节点的稳定性和可靠性。包括1min、5min和15min的数据。 图8 节点平均负载 节点CPU单核使用率 单位时间内节点单核CPU使用情况。 图9 节点CPU单核使用率 磁盘读I/O 节点磁盘近五分钟的数据读取次数。 图10 磁盘读I/O 磁盘写I/O 节点磁盘近五分钟的数据写入次数。 图11 磁盘写I/O Pod CPU使用率 单位时间内Pod CPU使用情况。 图12 Pod CPU使用率 Pod内存使用率 单位时间内Pod内存使用情况。 图13 Pod内存使用率 Pod状态趋势 实时监控节点Pod状态。 图14 Pod状态趋势 Pod数量变化趋势 节点已分配的容器组数量。 图15 Pod数量变化趋势
  • 策略实例示例 以下策略实例展示了策略定义生效的资源类型。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sPSPPrivilegedContainer metadata: name: psp-privileged-container spec: match: kinds: - apiGroups: [""] kinds: ["Pod"] excludedNamespaces: ["kube-system"]
  • 符合策略实例的资源定义 示例中privileged设置为false,符合策略实例。 apiVersion: v1 kind: Pod metadata: name: nginx-privileged-allowed labels: app: nginx-privileged spec: containers: - name: nginx image: nginx securityContext: privileged: false
  • 不符合策略实例的资源定义 示例中privileged设置为true,不符合策略实例。 apiVersion: v1 kind: Pod metadata: name: nginx-privileged-disallowed labels: app: nginx-privileged spec: containers: - name: nginx image: nginx securityContext: privileged: true
  • 不符合策略实例的资源定义 没有配置内存的Limit,CPU和内存的Request,不符合策略实例。 apiVersion: v1 kind: Pod metadata: name: opa-disallowed labels: owner: me.agilebank.demo spec: containers: - name: opa image: openpolicyagent/opa:0.9.2 args: - "run" - "--server" - "--addr=localhost:8080" resources: limits: memory: "2Gi"k8sexternalips
  • 符合策略实例的资源定义 已经配置内存的Limit,CPU和内存的Request,符合策略实例。 apiVersion: v1 kind: Pod metadata: name: opa-allowed labels: owner: me.agilebank.demo spec: containers: - name: opa image: openpolicyagent/opa:0.9.2 args: - "run" - "--server" - "--addr=localhost:8080" resources: limits: cpu: "100m" memory: "1Gi" requests: cpu: "100m" memory: "1Gi"
  • 策略实例示例 必须配置内存的Limit,CPU和内存的Request。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sRequiredResources metadata: name: container-must-have-cpu-requests-memory-limits-and-requests spec: match: kinds: - apiGroups: [""] kinds: ["Pod"] parameters: limits: - memory requests: - cpu - memory
  • 策略实例示例 以下策略实例定义容器镜像必须以“openpolicyagent/”开头。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sAllowedRepos metadata: name: repo-is-openpolicyagent spec: match: kinds: - apiGroups: [""] kinds: ["Pod"] namespaces: - "default" parameters: repos: - "openpolicyagent/"
  • k8clone备份使用方法 k8clone工具支持在Linux(x86、arm)和Windows环境中运行,使用方法相似。本文将以Linux(x86)环境为例进行介绍。 若使用Linux(arm)或Windows环境,请将下述命令中的k8clone-linux-amd64分别替换为k8clone-linux-arm64或k8clone-windows-amd64.exe。 在k8clone工具所在目录下执行./k8clone-linux-amd64 backup -h,可以查看k8clone工具备份的使用方法。 -k, --kubeconfig:指定kubectl的KubeConfig位置,默认是$HOME/.kube/config。kubeConfig文件:用于配置对Kubernetes集群的访问,KubeConfig文件中包含访问注册kubernetes集群所需要的认证凭据以及Endpoint(访问地址),详细介绍可参见Kubernetes文档。 -s, --api-server:Kubernetes API Server URL,默认是""。 -q, --context:Kubernetes Configuration Context,默认是""。 -n, --namespace:备份指定命名空间的云原生应用,多个命名空间用逗号分隔(如:ns1,ns2,ns3),默认是"",表示备份整个集群。 -e, --exclude-namespaces:排除指定命名空间对象的备份,不能和--namespace一起使用。 -x, --exclude-kind:排除指定资源类型的备份。 -y, --exclude-object:排除指定资源对象的备份。 -w, --exclude-having-owner-ref:排除拥有ownerReferences资源对象的备份,默认是false。 -d, --local-dir:备份数据放置的路径,默认是当前目录下k8clone-dump文件夹。 $ ./k8clone-linux-amd64 backup -h Backup Workload Data as yaml files Usage: k8clone backup [flags] Flags: -s, --api-server string Kubernetes api-server url -q, --context string Kubernetes configuration context -w, --exclude-having-owner-ref Exclude all objects having an Owner Reference -x, --exclude-kind strings Ressource kind to exclude. Eg. 'deployment' -e, --exclude-namespaces strings Namespaces to exclude. Eg. 'temp.*' as regexes. This collects all namespaces and then filters them. Don't use it with the namespace flag. -y, --exclude-object strings Object to exclude. Eg. 'configmap:kube-system/kube-dns' -h, --help help for backup -k, --kubeconfig string The kubeconfig of k8s cluster's. Default is the $HOME/.kube/config. -d, --local-dir string Where to dump yaml files (default "./k8clone-dump") -n, --namespace string Only dump objects from this namespace 示例如下: 整个集群对象的备份,默认路径为当前目录下“k8clone-dump”文件夹 ./k8clone-linux-amd64 backup 整个集群对象的备份,并指定备份数据路径 ./k8clone-linux-amd64 backup -d ./xxxx 指定命名空间对象的备份 ./k8clone-linux-amd64 backup -n default 排除命名空间对象的备份 ./k8clone-linux-amd64 backup -e kube-system,kube-public,kube-node-lease 排除指定资源类型的备份 ./k8clone-linux-amd64 backup -x endpoints,endpointslice 排除指定资源对象的备份 ./k8clone-linux-amd64 backup -y configmap:kube-system/kube-dns 排除拥有ownerReferences资源对象的备份 ./k8clone-linux-amd64 backup -w true
  • 接入网络模式 对于伙伴云集群,各集群提供商或本地数据中心对于网络入方向的端口规则有差异,防止特定端口外的入站通信。因此UCS使用集群网络代理的连接方式,如图2所示,无需在防火墙上启用任何入方向端口,仅通过集群代理程序的方式在出方向与UCS服务建立会话。 伙伴云集群接入网络的方法有两种,具有不同的优点: 公网接入:具有弹性灵活、成本低、易接入的优点。 私网接入:可获得更加高速、低时延、稳定安全的体验。 图2 集群接入原理
  • 基本信息 策略类型:合规 推荐级别:L1 生效资源类型:* 参数: annotations: 键值对数组,key/ allowedRegex key: a8r.io/owner # Matches email address or github user allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$
  • 策略实例示例 以下策略实例展示了策略定义生效的资源类型,parameters中指定了提示信息message以及annotations的约束定义。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sRequiredAnnotations metadata: name: all-must-have-certain-set-of-annotations spec: match: kinds: - apiGroups: [""] kinds: ["Service"] parameters: message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations." annotations: - key: a8r.io/owner # Matches email address or github user allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$ - key: a8r.io/runbook # Matches urls including or not http/https allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
  • 符合策略实例的资源定义 示例中的annotations符合策略实例。 apiVersion: v1 kind: Service metadata: name: allowed-service annotations: a8r.io/owner: "dev-team-alfa@contoso.com" a8r.io/runbook: "https://confluence.contoso.com/dev-team-alfa/runbooks" spec: ports: - name: http port: 80 targetPort: 8080 selector: app: foo
  • 策略实例示例 示例展示了ClusterRole和Role资源仅能关联到allowedRoles中定义的Role。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sDisallowAnonymous metadata: name: no-anonymous spec: match: kinds: - apiGroups: ["rbac.authorization.k8s.io"] kinds: ["ClusterRoleBinding"] - apiGroups: ["rbac.authorization.k8s.io"] kinds: ["RoleBinding"] parameters: allowedRoles: - cluster-role-1
  • 不符合策略实例的资源定义 ClusterRole关联到cluster-role-2 Role中,不符合策略实例。 apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: cluster-role-binding-2 roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-role-2 subjects: - apiGroup: rbac.authorization.k8s.io kind: Group name: system:authenticated - apiGroup: rbac.authorization.k8s.io kind: Group name: system:unauthenticated
  • 符合策略实例的资源定义 ClusterRole关联到cluster-role-1 Role中,符合策略实例。 apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: cluster-role-binding-1 roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-role-1 subjects: - apiGroup: rbac.authorization.k8s.io kind: Group name: system:authenticated - apiGroup: rbac.authorization.k8s.io kind: Group name: system:unauthenticated
  • 相关操作 通过UCS控制台,您还可以执行表2中的操作。 表2 相关操作 操作 说明 YAML创建 单击右上角“YAML创建”,可使用已有的YAML创建工作负载。 查看工作负载详情 单击已创建工作负载的名称,在“实例列表”页签下,可以查看Pod相关详情信息。 事件:可以设置查询条件,比如设置事件产生的时间段或搜索事件名称,查看相关事件。 容器列表:可以查看相应实例的容器名称、状态、镜像以及启停次数等。 查看YAML:可以查看相应实例的YAML文件。 编辑YAML 单击工作负载名称后的“编辑YAML”,可查看并编辑当前工作负载的YAML文件。 升级 单击工作负载名称后的“升级”。 更改工作负载信息,操作步骤与创建工作负载时一致。 单击“提交”,升级工作负载。 删除 单击工作负载名称后的“删除”,并单击“是”进行确认。 批量删除 勾选需要删除的工作负载。 单击左上角的“批量删除”。 单击“是”进行确认。
  • 符合策略实例的资源定义 示例中hostPID和hostIPC均为false,符合策略实例。 apiVersion: v1 kind: Pod metadata: name: nginx-host-namespace-allowed labels: app: nginx-host-namespace spec: hostPID: false hostIPC: false containers: - name: nginx image: nginx
  • 策略实例示例 以下策略实例展示了策略定义生效的资源类型。 apiVersion: constraints.gatekeeper.sh/v1beta1 kind: K8sPSPHostNamespace metadata: name: psp-host-namespace spec: match: kinds: - apiGroups: [""] kinds: ["Pod"]
  • 不符合策略实例的资源定义 示例中hostPID和hostIPC均为true,不符合策略实例。 apiVersion: v1 kind: Pod metadata: name: nginx-host-namespace-disallowed labels: app: nginx-host-namespace spec: hostPID: true hostIPC: true containers: - name: nginx image: nginx
共100000条