云服务器内容精选

  • 获取AK/SK AK(Access Key ID):访问密钥ID。与私有访问密钥关联的唯一标识符;访问密钥ID和私有访问密钥一起使用,对请求进行加密签名。 SK(Secret Access Key):与访问密钥ID结合使用的密钥,对请求进行加密签名,可标识发送方,并防止请求被修改。 登录管理控制台。 单击用户名,在下拉列表中单击“我的凭证”。 在“我的凭证”页面,单击“访问密钥”页签。 单击“新增访问密钥”,输入验证码。 单击“确定”,生成并下载访问密钥。 为防止访问密钥泄露,建议您将其保存到安全的位置。
  • 非安全环境配置kubectl 参照上述操作,安装并设置kubectl。 编辑KubeConfig文件,删除敏感信息参数。 Linux系统,KubeConfig文件默认位于$HOME/.kube/config。 表2 待删除敏感信息参数 Command Flag Environment Value Description --domain-name DOMAIN_NAME 租户名 --user-name USER_NAME 子用户名 --password PASSWORD 用户密码 --ak AC CES S_KEY_ID Access Key --sk SECRET_ACCESS_KEY Secret Key --cache CREDENTIAL_CACHE 是否开启缓存Token 更多参数说明请参见asm-iam-authenticator使用参考。 配置删除参数相应的环境变量来使用kubectl,以CREDENTIAL_CACHE为例,其他环境变量如ACCESS_KEY_ID和SECRET_ACCESS_KEY可参考CREDENTIAL_CACHE进行配置。 export CREDENTIAL_CACHE=false 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全。 kubectl get serviceentry -n xxx 执行上述命令后,提示如下类似信息:
  • 获取网格实例Endpoint 登录华为云U CS 控制台,左侧菜单栏选择“服务网格”。 F12打开浏览器console切换到“网络”标签页,单击服务网格列表页右上角小刷新按钮,找到meshes接口,单击“预览”标签页,找到对应网格的返回体,找到status.meshEndpoint.vpcEndpointServiceName字段后复制。 登录 VPC终端节点 VPCEP,左侧菜单栏选择“终端节点”,找到终端节点服务名称为步骤2获取到的对应的终端节点,单击进入获取到节点IP。 ASM在您创建网格时选择的枢纽VPC创建终端节点,并将该终端节点连接到网格控制面apiserver,来打通访问网格控制面的网络。更多信息请参考1.2-操作步骤中VPC解释。
  • 下载asm-iam-authenticator 在ASM官网下载asm-iam-authenticator二进制,最新版本为v1.0.0,下载地址如表1所示。 表1 下载地址 操作系统 下载地址 查看帮助 Linux AMD 64位 asm-iam-authenticator_linux-amd64 asm-iam-authenticator_linux-amd64_sha256 asm-iam-authenticator使用参考
  • 安装并设置kubectl 以下操作以Linux环境为例,更多详情信息请参见安装和配置kubectl。 1、以下步骤需要在UCS网格接入集群纳管的节点上操作。 2、以下步骤2执行asm-iam-authenticator generate-kubeconfig命名后会更新节点默认配置的config内容,建议执行以下命令备份config文件。 cp $HOME/.kube/config $HOME/.kube/config.backup 将下载kubectl中下载的kubectl赋予可执行权限,并放到PATH目录下。 chmod +x ./kubectl mv ./kubectl $PATH 其中,$PATH为PATH路径(如/usr/local/bin),请替换为实际的值。 您还可以通过如下命令查看kubectl的版本,如下所示。 kubectl version --client=true Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-12T10:57:26Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"linux/amd64"} Kustomize Version: v4.5.7 配置 IAM 认证信息并持久化到本地。 将下载asm-iam-authenticator中下载的asm-iam-authenticator赋予可执行权限,并放到PATH目录下。 chmod +x ./asm-iam-authenticator mv ./asm-iam-authenticator $PATH 初始化asm-iam-authenticator配置。 初始化asm-iam-authenticator提供了AK/SK和用户名/密码两种方式,请选择其中一种执行。 使用AK/SK的方式配置IAM认证信息 asm-iam-authenticator generate-kubeconfig --iam-endpoint=https://$iam_endpoint --mesh-endpoint=https://$mesh_endpoint --mesh-region=$mesh_region --ak=xxxxxxx --sk=xxxxxx 其中, iam_endpoint为IAM服务的Endpoint,请参见地区和终端节点 mesh_endpoint为网格实例的Endpoint,获取方法请参见获取网格实例Endpoint; mesh_region为网格所在区域; ak、sk的获取方法请参见获取AK/SK,ak为文件中Access Key部分,sk为文件中Secret Key部分。 例如,iam_endpoint为https://iam.cn-north-4.myhuaweicloud.com,mesh_endpoint为https://xx.xx.xx.xx:5443, mesh_region为cn-north-4, ak的值为my-ak,sk的值为ABCDEFAK.. ,则命令如下所示: asm-iam-authenticator generate-kubeconfig --iam-endpoint=https://iam.cn-north-4.myhuaweicloud.com --mesh-endpoint=https://xx.xx.xx.xx:5443 --mesh-region=cn-north-4 --ak=my-ak --sk=ABCDEFAK.. 执行上述命令后,显示如下类似信息: Switched to context "asm-context-cn-north-4-my-ak" 其中,asm-context-cn-north-4-my-ak为context名,可通过kubectl config get-contexts命令查看。 使用用户名/密码的方式配置IAM认证信息 asm-iam-authenticator generate-kubeconfig --iam-endpoint=https://$iam_endpoint --mesh-endpoint=https://$mesh_endpoint --mesh-region=$mesh_region --domain-name=xxxxxxx --user-name=xxxxxx --password='xxxxxx' 其中,iam_endpoint为IAM服务的Endpoint,请参见地区和终端节点, mesh_endpoint为网格实例的Endpoint,获取方法请参见获取网格实例Endpoint; mesh_region为网格所在区域; domain-name为租户名,user-name为子用户名,password为子用户密码,请根据替换为实际的值。 若无子用户,user-name与domain-name配置一致即可,也可以不添加user-name参数。 IAM的Endpoint请参见地区和终端节点,请注意需要使用与网格实例地区相同的Endpoint。 在非安全的环境中使用kubectl,建议您完成此步骤后,使用环境变量的方式重新配置认证信息,具体参考非安全环境配置kubectl。 配置完成后,即可通过kubectl命令操作网格实例的相关资源。 例如,查看北京四的namespace资源。 kubectl get serviceentry -n xxx 执行上述命令后,提示如下类似信息: 当通过API访问公有云系统时,需要使用访问用户名密码或者密钥(AK/SK)进行身份认证并对请求进行加密,确保请求的机密性、完整性和请求双方身份的正确性。请妥善保存$HOME/.kube/config配置文件,确保访问密钥不被非法使用。 当开启cache缓存token提高访问性能时,token会以文件的方式保存在$HOME/.asm/cache的子目录下,请及时清理。 当发现访问密钥被非法使用(包括丢失、泄露等情况),可以自行删除或者通知管理员重置访问密钥,重新配置。 删除的访问密钥将无法恢复。
  • asm-iam-authenticator使用参考 asm-iam-authenticator作为k8s client端的认证插件,主要提供了generate-kubeconfig和token两个子命令。 A tool to authenticate to ASM using HuaweiCloud IAM credentials Usage: asm-iam-authenticator [command] Available Commands: completion Generate the autocompletion script for the specified shell generate-kubeconfig Generate or modify kubeconfig files based on user configuration help Help about any command token Authenticate using HuaweiCloud IAM and get token for ASM Flags: --alsologtostderr log to standard error as well as files (no effect when -logtostderr=true) -h, --help help for asm-iam-authenticator --log_dir string If non-empty, write log files in this directory (no effect when -logtostderr=true) --log_file string If non-empty, use this log file (no effect when -logtostderr=true) --logtostderr log to standard error instead of files (default true) -v, --v Level number for the log level verbosity --version version for asm-iam-authenticator Use "asm-iam-authenticator [command] --help" for more information about a command. 其中,Flags主要为日志选项。 token token子命令用于获取用户token,获取token的认证方式有用户名/密码、ak/sk两种,选择其中一种即可。 Authenticate using HuaweiCloud IAM and get token for ASM Usage: asm-iam-authenticator token [flags] Flags: --ak string IAM access key ID --aksk-dir string The directory of IAM access key(AK) and secret access key(SK) --cache Cache the token credential on disk until it expires (default true) --domain-name string IAM domain name, typically your account name -h, --help help for token --iam-endpoint string HuaweiCloud IAM endpoint, i.e. https://iam.cn-north-4.myhuaweicloud.com (default "https://iam.myhuaweicloud.com") --insecure-skip-tls-verify If true, the iam server's certificate will not be checked for validity. (default true) --password string IAM user password --project-id string IAM project id, project id and project name should not be empty at same time --project-name string IAM project name, project id and project name should not be empty at same time --sk string IAM secret access key --token-expired-refresh Whether refresh the cached token when it may have expired resulting unauthorized. If true, we will use client.authentication.k8s.io/v1alpha1 api version. Otherwise, use client.authentication.k8s.io/v1beta1 --token-only Return token only for other tool integration --user-name string IAM user name. Same as domain-name when using main account, otherwise use iam user name 其中,Flags分为用户名密码、AKSK和公共配置。 表1 用户名/密码配置 Command Flag Environment Value Description domain-name DOMAIN_NAME 租户名,即账号名,详情请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0001.html。 user-name USER_NAME 子用户名,即IAM用户名。若不配置与domain-name一致。 详情请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0001.html。 password PASSWORD 用户或子用户密码。 表2 AK/SK配置 Command Flag Environment Value Description ak ACCESS_KEY_ID ak、sk的获取方法请参见获取AK/SK,ak为文件中Access Key部分,sk为文件中Secret Key部分。 sk SECRET_ACCESS_KEY 表3 公共配置 Command Flag Environment Value Description iam-endpoint IAM_ENDPOINT IAM的Endpoint,必须配置,详情请参见https://developer.huaweicloud.com/endpoint?IAM。 project-name PROJECT_NAME 项目名,详情请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0001.html。 project-id PROJECT_ID 项目ID,详情请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0001.html。 insecure-skip-tls-verify INSECURE_SKIP_TLS_VERIFY 是否跳过对CCI/IAM服务端的校验,默认为true。 cache CREDENTIAL_CACHE 是否开启将IAM Token缓存到本地,提高访问性能,默认为true。 注意: 在非安全环境,建议关闭此选项。 generate-kubeconfig 为用户直接生成KubeConfig配置,若指定的KubeConfig已存在,则会注入新的server、user、context配置,并将当前的KubeConfig context切换到此次配置的结果。 Generate or modify kubeconfig files based on user configuration. Sets a cluster entry, a user entry and a context entry in kubeconfig and use this context as the current-context. The loading order follows these rules: 1. If the --kubeconfig flag is set, then only that file is loaded. The flag may only be set once and no merging takes place. 2. If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for your system). These paths are merged. When a value is modified, it is modified in the file that defines the stanza. When a value is created, it is created in the first file that exists. If no files in the chain exist, then it creates the last file in the list. 3. Otherwise, ${HOME}/.kube/config is used and no merging takes place. Examples: # Generate kubeconfig to ${HOME}/.kube/config using aksk asm-iam-authenticator generate-kubeconfig --mesh-endpoint=https://127.0.0.1:5443 --ak=*** --sk=*** # Generate kubeconfig to ${HOME}/.kube/config using domain name and password asm-iam-authenticator generate-kubeconfig --mesh-endpoint=https://127.0.0.1:5443 --domain-name=*** --password=*** Usage: asm-iam-authenticator generate-kubeconfig [flags] Flags: --ak string IAM access key ID --aksk-dir string The directory of IAM access key(AK) and secret access key(SK) --cache Cache the token credential on disk until it expires (default true) --domain-name string IAM domain name, typically your account name -h, --help help for generate-kubeconfig --iam-endpoint string HuaweiCloud IAM endpoint, i.e. https://iam.cn-north-4.myhuaweicloud.com (default "https://iam.myhuaweicloud.com") --insecure-skip-tls-verify If true, the iam server's certificate will not be checked for validity. (default true) --kubeconfig string use a particular kubeconfig file --mesh-endpoint string Mesh server endpoint, i.e. https://127.0.0.1:5443 --mesh-region string Mesh region, i.e. cn-north-4 --password string IAM user password --project-id string IAM project id, project id and project name should not be empty at same time --project-name string IAM project name, project id and project name should not be empty at same time --sk string IAM secret access key --token-expired-refresh Whether refresh the cached token when it may have expired resulting unauthorized. If true, we will use client.authentication.k8s.io/v1alpha1 api version. Otherwise, use client.authentication.k8s.io/v1beta1 --token-only Return token only for other tool integration --user-name string IAM user name. Same as domain-name when using main account, otherwise use iam user name --validation Validate kubeconfig by trying to access Mesh with existing config (default true) 父主题: 使用kubectl连接网格控制面