当前位置:网站首页>How to access tke cluster API interface with certificate or token
How to access tke cluster API interface with certificate or token
2022-06-24 16:33:00 【Nieweixing】
Use k8s We often visit the cluster during the process of api Interface , But usually k8s Of apiserver It's all used https authentication , When we want to visit directly api The interface needs to be authenticated , This is in tke The same is true in clusters , So when we need to code or use curl Ask to visit tke Clustered api What about interfaces ? Let's talk about using client certificates or clusters token To visit tke Clustered api Interface .
1. Client certificate access tke colony api Interface
Since we want to use the client certificate to access api, So where does the certificate come from ? Actually tke Clustered kubeconfig All of them are certified by certificates , Every user has their own kubeconfig, There are client certificates used to communicate with apiserver For authentication , So we can go straight from kubeconfig Extract the required client certificate from .
Enter into kubelet Of kubeconfig Under the table of contents
cd /etc/kubernetes
Execute the following commands in turn , Respectively from the kubeconfig Get in file cert、key and apiserver Information
cat ./kubelet-kubeconfig |grep client-certificate-data | awk -F ' ' '{print $2}' |base64 -d > client-cert.pem
cat ./kubelet-kubeconfig |grep client-key-data | awk -F ' ' '{print $2}' |base64 -d > client-key.pem
APISERVER=`cat ./kubelet-kubeconfig |grep server | awk -F ' ' '{print $2}'`
And then execute cur Command access apiserver
curl --cert client-cert.pem --key client-key.pem -k $APISERVER/api/
Get all the namespace
curl --cert client-cert.pem --key client-key.pem -k $APISERVER/api/v1/namespaces
Here are not all examples , Access to other interfaces , Please refer to the official documents https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/ .
perform curl The following error messages will appear during command access
Because this is where curl The request is for an anonymous user , Anonymous users generally do not have sufficient permissions in the cluster , So we need to go through rbac Bind anonymous users clusterrole, Here we bind the administrator role of the cluster tke:admin, Then the visit will be ok
kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=tke:admin --user=system:anonymous
2. token Access cluster api
Everybody knows tke The cluster is on rbac after , Each account number passes the certificate and apiserver authentication , No more token, But if we need to use token It's still available , Refer to the document for specific acquisition methods https://cloud.tencent.com/developer/article/1762567 , Get the cluster according to the document token after ,apiserver The address of can be according to the above APISERVER How to get ,token and apiserver The addresses have been obtained , Then you can visit api 了 . Be careful , for fear of token Leaked , below token Are all modified .
Get clusters api Interface
curl -k -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsIZXQubmFtZSI6InRrZS1hZG1pbi10b2tlbi1od3F3MiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJ0a2UtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJiMTJhYzU0Yi02N2I1LTQymYiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDp0a2UtYWRtaW4ifQ.cVvAALd2ARAFwm5eMmrIxu2mbMB8fcvKiDlKO05-oYwBiKxagBJnZN2TQsANRkGzdMUp0IaZrZXpvvt4R48Fe5qxIzNkF7tvi0ZOQ4cY75jS7ZcpIVqRhUHGcRh8DOemWGa940UAF_k5CWX1Xf4y_odAEM-rW5IIsLesWXfdoBkf5PHfnD_XKGHBTZ0Io0OKC_cRNDQrxCYCRglcXNojCksHFec1bQVmUQpeVlkH8iAtvvpUHknM9W5KpwCeYmMgre0fVmy8v1wzLOSFrKWIBTJ_VZRoc7qMKFVRpszzoDtjfehLcJ-uualdCaXe0utsB2w9Sk15jnZtEyCb3qveZQ" https://cls-xxxxxx.ccs.tencent-cloud.com
Get the cluster's namespace
curl -k -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImphQ0RWTFBlNTJ0aXNDSUNkTUJzdHBlbTBLSFVGTmd0UF9JWGMwOFNqM2MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhYNvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2Uiy9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6InRrZS1hZG1pbi10b2tlbi1od3F3MiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJ0a2UtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJiMTJhYzU0Yi02N2I1LTQyNjktOTc3MC0xMGE5MTIzNDhhZmYiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmY2mbMB8fcvKiDlKO05-oYwBiKxagBJnZN2TQsANRkGzdMUp0IaZrZXpvvt4R48Fe5qxIzNkF7tvi0ZOQ4cY75jS7ZcpIVqRhUHGcRh8DOemWGa940UAF_k5CWX1Xf4y_odAEM-rW5IIsLesWXfdoBkf5PHfnD_XKGHBTZ0Io0OKC_cRNDQrxCYCRglcXNojCksHFec1bQVmUQpeVlkH8iAtvvpUHknM9W5KpwCeYmMgre0fVmy8v1wzLOSFrKWIBTJ_VZRoc7qMKFVRpszzoDtjfehLcJ-uualdCaXe0utsB2w9Sk15jnZtEyCb3qveZQ" https://cls-xxxx.ccs.tencent-cloud.com//api/v1/namespaces
Here are not all examples , Access to other interfaces , Please refer to the official documents https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.21/
Here we can also use postman To visit , Fill in token and apiserver The address of , Then make a request .
边栏推荐
- sql 多表更新数据非常慢
- Detailed explanation of transpose convolution in pytorch
- [tke] modify the cluster corendns service address
- AI structured intelligent security video monitoring technology, supporting the protective umbrella of the reserve / wild animals
- Use Google search like a professional
- Funny! Pictures and texts give you a comprehensive understanding of the effects of dynamics and mass
- Global and Chinese markets of Leyte coin exchange 2022-2028: Research Report on technology, participants, trends, market size and share
- Siggraph 2022 | truly restore the hand muscles. This time, the digital human hands have bones, muscles and skin
- 2021 devopsdays Tokyo Station ends perfectly | coding experts are invited to share the latest technical information
- It may be a good idea to use simulation software in the cloud for simulation
猜你喜欢
ZOJ - 4104 sequence in the pocket
Some adventurer hybrid versions with potential safety hazards will be recalled
MySQL Advanced Series: locks - locks in InnoDB
Applet wxss
Advanced programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization
Problems encountered in the work of product manager
ZOJ——4104 Sequence in the Pocket(思维问题)
B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)
MySQL Advanced Series: Locks - Locks in InnoDB
A new weapon to break the memory wall has become a "hot search" in the industry! Persistent memory enables workers to play with massive data + high-dimensional models
随机推荐
Pytorch transpose convolution
How to pop up an alarm through the national standard gb28181 protocol video platform easygbs for mobile detection / perimeter intrusion detection video recording
Experience and suggestions on cloud development database
Fastjson vulnerability utilization techniques
Don't let [mana] destroy your code!
Summer Challenge harmonyos - to do list with date effect
对深度可分离卷积、分组卷积、扩张卷积、转置卷积(反卷积)的理解
Istio FAQ: virtualservice route matching sequence
Go deep into the implementation principle of go language defer
Ps\ai and other design software pondering notes
Modern finite element analysis can easily achieve accurate results
An error is reported during SVN uploading -svn sqlite[s13]
Development trend of CAE simulation analysis software
Cloud + community [play with Tencent cloud] video solicitation activity winners announced
嵌入式开发基础之线程间通信
Transpose convolution learning notes
Object store signature generation
Global and Chinese market for commercial barbecue smokers 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of computer protective film 2022-2028: Research Report on technology, participants, trends, market size and share
Goby+AWVS 实现攻击面检测