当前位置:网站首页>In aks, use secret in CSI driver mount key vault
In aks, use secret in CSI driver mount key vault
2022-07-01 16:58:00 【mxy00000】
What will this article introduce , You should be able to see it in the title , This article mainly introduces how to AKS Lieutenant general Azure Key Vault Medium secret mount To storage in , This scenario should be regarded as a very standard security design , For example, some confidential information is generally recommended to be placed in Key Vault in , It would be safer , for instance , Database or application username and pwd, Put it in Key Vault in , And then let pod Auto read key vault Information in , This can avoid the risk of information disclosure to the greatest extent
And if you want to achieve this , You need to use the content introduced today , Mainly through CSI driver To achieve , It used to be called Flex Volume, obtain secret The content in must have permission , There are many ways to get authorization , Include service principal,pod identity,vmss identity Many other kinds , This time, we mainly use service principal The way
First of all, I will briefly introduce the contents that need to be prepared , It contains so many things
- One AKS Cluster
- One SP, And corresponding client id and pwd
- One Key Vault, stay Key Vault Configure some in secret
- add to Access Policy to SP Authorized access secret
- For deployment yaml file
establish cluster,service principal(SP) as well as key vault I won't introduce the steps of
Go straight to work , Take a look first key vault The following secret

Now add a access policy, to service principal grant secret Of get,list jurisdiction

Then first K8S Create a secret, This secret Will contain service principal Of id and pwd,csi driver Will read this secret And then through service principal Of id and pwd Get token, Then pull key vault Inside secret
kubectl create secret generic keyvaultsecret
--from
-literal
clientid
=<AZURE_CLIENT_ID>
--from
-literal
clientsecret
=<AZURE_CLIENT_SECRET>
kubectl label secret keyvaultsecret secrets-store.csi.k8s.io
/used
=
true
- 1.
- 2.

Next, prepare for deployment yaml file ,yaml There are two main documents
- SecretProviderClass yaml, Used to describe what to get secret And how to get secret
- App yaml, Regular application deployment yaml, contain mountpath And the use of secret
SecretProviderClass yaml
apiVersion
secrets-store.csi.x-k8s.io/v1
kind
SecretProviderClass
metadata
name
"spc-keyvault"
namespace
"default"
spec
provider
azure
parameters
usePodIdentity
"false"
useVMManagedIdentity
"false"
userAssignedIdentityID
"***"
# Service Principal ID
keyvaultName
"mxyvault"
objects
array:
- |
objectName: username
objectType: secret
- |
objectName: userpwd
objectType: secret
tenantId
"****"
# tenant ID
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
App yaml
apiVersion
apps/v1
kind
Deployment
metadata
labels
app
apachesecret
name
apachesecret
spec
replicas
2
selector
matchLabels
app
apachesecret
strategy
rollingUpdate
maxSurge
1
maxUnavailable
1
type
RollingUpdate
template
metadata
labels
app
apachesecret
name
apachesecret
spec
containers
image
*****
livenessProbe
httpGet
path
/
port
80
initialDelaySeconds
30
periodSeconds
20
timeoutSeconds
10
failureThreshold
3
imagePullPolicy
Always
name
apachesecret
volumeMounts
mountPath
"/mnt/secrets-store"
name
secrets-store-inline
readOnly
true
volumes
csi
driver
secrets-store.csi.k8s.io
nodePublishSecretRef
name
keyvaultsecret
readOnly
true
volumeAttributes
secretProviderClass
"spc-keyvault"
name
"secrets-store-inline"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
It's a simple one demo It's almost done , Next, before deployment , You need to give it first AKS Turn on add on, otherwise secret provider class This resource Will not be recognized
az aks enable-addons
--addons azure-keyvault-secrets-provider
--name myAKSCluster
--resource
-group myResourceGroup
- 1.

Then you can start deployment
kubectl apply
-f
"D:\UserData\Desktop\ApacheSecretProviderClassyml.yaml"
kubectl apply
-f
"D:\UserData\Desktop\ApacheSecretDeployment.yml"
- 1.
- 2.

You can see pod It's already running
kubectl
get po
- 1.

And into pod in , You can also see secret Have succeeded pull down

边栏推荐
- Ring iron pronunciation, dynamic and noiseless, strong and brilliant, magic wave hifiair Bluetooth headset evaluation
- 剑指 Offer II 015. 字符串中的所有变位词
- P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
- Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
- ShenYu 网关开发:在本地启用运行
- 挖财学堂班主任给的证券账户安全吗?能开户吗?
- sql刷题584. 寻找用户推荐人
- AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
- String class
- 拼接字符串,得到字典序最小的结果
猜你喜欢

多线程并发之CountDownLatch阻塞等待

免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!

Ring iron pronunciation, dynamic and noiseless, strong and brilliant, magic wave hifiair Bluetooth headset evaluation

Pytest learning notes (13) -allure of allure Description () and @allure title()

游戏行业安全选择游戏盾,效果怎么样?

sql刷题584. 寻找用户推荐人

SQL question brushing 627 Change gender

Detailed explanation of activity life cycle and startup mode

Bugku's file contains

How to use etcd to realize distributed /etc directory
随机推荐
How to solve the keyboard key failure of notebook computer
Rhcsa Road
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
Leetcode records - sort -215, 347, 451, 75
Cookies and session keeping technology
[wrung Ba wrung Ba is 20] [essay] why should I learn this in college?
模板引擎Velocity 基礎
走进微信小程序
Judge whether the binary tree is a binary search tree
阿里云、追一科技抢滩对话式AI
中国锦纶长丝缝纫线发展预测与投资方向研究报告(2022版)
Basic use of MySQL
【Kotlin】高阶函数介绍
Introduction to software engineering - Chapter 6 - detailed design
SQL question brushing 1050 Actors and directors who have worked together at least three times
为什么你要考虑使用Prisma
[mathematical modeling] [matlab] implementation of two-dimensional rectangular packing code
[pyg] document summary and project experience (continuously updated
【直播预约】数据库OBCP认证全面升级公开课
sql刷题584. 寻找用户推荐人