当前位置:网站首页>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 .
边栏推荐
- What is cloud development? Why cloud development? Talk about our story
- How to open a futures account safely? Which futures companies are more reliable?
- ThinkPHP vulnerability exploitation tool
- Istio FAQ: virtualservice route matching sequence
- Global and Chinese markets of stainless steel barbecue ovens 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of Leyte coin exchange 2022-2028: Research Report on technology, participants, trends, market size and share
- An error is reported during SVN uploading -svn sqlite[s13]
- Istio FAQ: failed to resolve after enabling smart DNS
- 2021-05-03: given a non negative integer num, how to avoid circular statements,
- A set of very good H3C and Tianrongxin Internet cutover scheme templates, with word document download
猜你喜欢

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

Applet - use of template

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

Siggraph 2022 | truly restore the hand muscles. This time, the digital human hands have bones, muscles and skin

Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021

Applet wxss

One article explains Jackson configuration information in detail

ZOJ——4104 Sequence in the Pocket(思维问题)
MySQL Advanced Series: locks - locks in InnoDB

Ui- first lesson
随机推荐
Summer Challenge harmonyos - to do list with date effect
@There is a free copyright protection service for enterprises in Dawan District
A set of very good H3C and Tianrongxin Internet cutover scheme templates, with word document download
Object store signature generation
Interpretation of swin transformer source code
ThinkPHP vulnerability exploitation tool
Pytorch transpose convolution
2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
AI video structured intelligent security platform easycvr realizes intelligent security monitoring scheme for procuratorate building
ZOJ - 4104 sequence in the pocket
How to open a futures account safely? Which futures companies are more reliable?
What is the difference between get and post? After reading it, you won't be confused and forced, and you won't have to fight with your friends anymore
Abnormal dockgeddon causes CPU 100%
B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)
Go deep into the implementation principle of go language defer
How FEA and FEM work together
Some adventurer hybrid versions with potential safety hazards will be recalled
国泰君安期货安全么?期货开户怎么开?期货手续费怎么降低?
Experience and suggestions on cloud development database
Global and Chinese market of music synthesizer 2022-2028: Research Report on technology, participants, trends, market size and share