linux cpu占用率如何看
290
2022-09-29
在AKS中使用pod identity获取token - 实践
下边开始来实际跑个demo,看下具体在使用时pod identity能达到什么样的效果,这是pod identity官方给的一个sample,要做的工作主要分为几个步骤
部署pod identity创建Azure user assigned identity准备yaml文件,部署Azure identity和Azure identity binding部署测试用的yaml
环境准备
需要准备的实验环境很简单,主要包括以下资源和工具
使用Azure CNI网络模型的AKS集群kubectlAzure CLI
实践环节
准备环境变量
$RESOURCE_GROUP='Apache'$CLUSTER_NAME='SSLAKS'$IDENTITY_RESOURCE_GROUP="$(az aks show -g $RESOURCE_GROUP -n $CLUSTER_NAME --query nodeResourceGroup -o tsv)"$IDENTITY_NAME="demo"
部署pod identity component
pod identity的部署基本和其他产品差不多,完全通过yaml文件直接部署即可
kubectl apply -f For AKS clusters, deploy the MIC and AKS add-on exception by running -kubectl apply -f get crd -A
也出现了新的API Resource
kubectl api-resources|?{$_ -like '*identity*'}
还会部署mic和nmi两个核心组件的pod
创建user assigned identity
pod identity本身并不会知道应该给谁获取什么样的权限,而是需要用户告诉pod identity希望获取什么样的权限,而要做到这点,就需要指定在pod identity中要是用的是service principal,还是managed identity,然后把对应的信息写在Azure identity的yaml文件里
因为是个sample的环境,所以我们直接新创建一个user assigned identity来给pod identity用
az identity create -g $IDENTITY_RESOURCE_GROUP -n $IDENTITY_NAME
其实就是个user assigned managed identity
获取client id和resource id
$IDENTITY_CLIENT_ID="$(az identity show -g $IDENTITY_RESOURCE_GROUP -n $IDENTITY_NAME --query clientId -o tsv)"$IDENTITY_RESOURCE_ID="$(az identity show -g $IDENTITY_RESOURCE_GROUP -n $IDENTITY_NAME --query id -o tsv)"
准备工作做好之后,即可开始准备pod identity测试用的部署文件
创建Azure identity
apiVersion: "aadpodidentity.k8s.io/v1"kind: AzureIdentitymetadata: name: ${IDENTITY_NAME}spec: type: 0 resourceID: ${IDENTITY_RESOURCE_ID} clientID: ${IDENTITY_CLIENT_ID}
Type 可以有多种取值范围,分别代表不同含义,部署用的就是0,也就是user assigned identity:
type: 0 user-assigned MSItype: 1 Service Principal with client secrettype: 2 Service Principal with certificate
kubectl apply -f "D:\UserData\Desktop\Pod Identity\AzureIdentitySample.yml"kubectl get azureidentity
创建AzureIdentityBinding
准备yaml文件,把变量替换为实际环境的值
apiVersion: "aadpodidentity.k8s.io/v1"kind: AzureIdentityBindingmetadata: name: ${IDENTITY_NAME}-bindingspec: azureIdentity: ${IDENTITY_NAME} selector: ${IDENTITY_NAME}
kubectl apply -f "D:\UserData\Desktop\Pod Identity\AzureIdentityBindingSample.yml"kubectl get azureidentitybinding
部署测试用pod
准备yaml文件,把变量替换为实际环境的值
哪些pod可以使用identitybinding是靠pod中aadpodidbinding这个字段去区分的,这个字段的值就是之前identitybinding yaml文件中selector字段对应的值,两者要匹配起来
apiVersion: v1kind: Podmetadata: name: demo labels: aadpodidbinding: $IDENTITY_NAMEspec: containers: - name: demo image: mcr.microsoft.com/oss/azure/aad-pod-identity/demo:v1.8.4 args: - --subscription-id=${SUBSCRIPTION_ID} - --resource-group=${IDENTITY_RESOURCE_GROUP} - --identity-client-id=${IDENTITY_CLIENT_ID} nodeSelector: kubernetes.io/os: linux
开始部署
kubectl apply -f "D:\UserData\Desktop\Pod Identity\AzureIdentitySamplePod.yml"kubectl get po|?{$_ -like 'pod*'}
查看部署pod的log,可以找到获取到token这种字眼
kubectl logs pod-identity-demo
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~