当前位置:网站首页>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.pemcat ./kubelet-kubeconfig |grep client-key-data | awk -F ' ' '{print $2}' |base64 -d > client-key.pemAPISERVER=`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 .
边栏推荐
- Enterprise security attack surface analysis tool
- Goby+awvs realize attack surface detection
- Little red book, hovering on the edge of listing
- 【prometheus】1. Monitoring overview
- Interpretation of swin transformer source code
- Global and Chinese markets of stainless steel barbecue ovens 2022-2028: Research Report on technology, participants, trends, market size and share
- Ui- first lesson
- Funny! Pictures and texts give you a comprehensive understanding of the effects of dynamics and mass
- What is cloud development? Why cloud development? Talk about our story
- Global and Chinese market of computer protective film 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
MySQL Advanced Series: locks - locks in InnoDB

Ui- first lesson

C. Three displays codeforces round 485 (Div. 2)

C. Three displays(动态规划)Codeforces Round #485 (Div. 2)

ZOJ - 4104 sequence in the pocket

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

C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)

B. Ternary Sequence(思维+贪心)Codeforces Round #665 (Div. 2)
MySQL進階系列:鎖-InnoDB中鎖的情况

Applet wxss
随机推荐
Introduction of thread pool and sharing of practice cases
Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
One article explains Jackson configuration information in detail
2021-04-29: given an array arr, it represents a row of balloons with scores. One for each blow
B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)
How to open a futures account safely? Which futures companies are more reliable?
What can Lu yuanjiu Jiao buy?
What is zero trust? Three classes will show you how to understand him!
ZOJ——4104 Sequence in the Pocket(思维问题)
Annual contribution! Tencent cloud middleware product upgrade conference is in hot registration!
[idea] dynamic planning (DP)
2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
[play with Tencent cloud] my operation strategy from domain name application to website filing in Tencent cloud
Load MySQL table data consumption quick installation configuration through kafka/flink
ThinkPHP 漏洞利用工具
Kubernetes popular series: getting started with container Foundation
April 26, 2021: the length of the integer array arr is n (3 < = n < = 10^4), and each number is
炒期货在哪里开户最正规安全?怎么期货开户?
MySQL timestamp format conversion date format string
#夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项