当前位置:网站首页>Tke accesses the cluster through kubectl in pod
Tke accesses the cluster through kubectl in pod
2022-06-24 03:11:00 【Nieweixing】
Now, all kinds of cloud vendors provide managed services k8s service , And there is a visual front end to access the resources in the cluster , Again tke The same is true of clusters , But as a k8s Users of , use kubectl To access the cluster is essential ,tke The console does not display all resource types , Like some custom crd You can only view it by command , And there is a console to check in time , Many big men are still used to command . However, the permissions on the cloud are generally strictly controlled , You may only have console permissions , You do not have permission to log in to the machine , Or your cluster does not have public network access enabled , Only intranet access , How to pass this time kubectl To access the cluster ?
Now let's go through tke Deploy a... Within the cluster kubectl Of pod, To access the cluster as a client apiserver, The premise is that you can operate on the console tke colony .
1. adopt configmap Mount cluster kubeconfig
1.1 The console gets kubeconfig
If you can operate the console tke The cluster describes the... Under your account kubeconfig There is authority , Access the basic information page of the cluster kubeconfig
1.2 Get clusters apiserver Internal visits ip Address
the reason being that kubectl In the cluster pod, So we went through apiserver Of cluserip Just visit , Get next default Under the namespace kubernetes This service Of clusterip, The port is 443.
1.3 establish configmap
Refer to the following modification yaml, adopt configmap Put our revised kubeconfig Mount to pod, What needs to be noted here is that the console will get Kubeconfig In file clusters.cluster.server Replace the field with https://<kubernetes svc Of clusterip>:443 that will do .
apiVersion: v1
data:
config: |-
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZ
server: https://172.16.0.1:443
name: cls-xxxx
contexts:
- context:
cluster: cls-xxxx
user: "xxxxx"
name: cls-xxxxx-xxxxx-context-default
current-context: cls-xxxx-xxxxx-context-default
kind: Config
preferences: {}
users:
- name: "xxxxxx"
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJU
client-key-data: LS0tLS1CRUdJTiBSU0EgUFJJVk
kind: ConfigMap
metadata:
name: config
namespace: tke-test
2. Deploy kubectl The workload
Here we deploy the workload , And mount the configmap, Give Way kubectl It can be read directly by default kubeconfig, because kubectl The image has no resident process , So here's a sleep As pod Resident process , visit pod I can't get up .
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: kubectl
qcloud-app: kubectl
name: kubectl
namespace: tke-test
spec:
replicas: 1
selector:
matchLabels:
k8s-app: kubectl
qcloud-app: kubectl
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
k8s-app: kubectl
qcloud-app: kubectl
spec:
containers:
- args:
- 3600d
command:
- sleep
image: mohamedltaief/kubctl-helm:latest
imagePullPolicy: Always
name: kubectl
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 250m
memory: 256Mi
securityContext:
privileged: false
volumeMounts:
- mountPath: /root/.kube/config
name: vol
subPath: config
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: qcloudregistrykey
restartPolicy: Always
volumes:
- configMap:
defaultMode: 420
name: config
name: vol3. Test access cluster
pod After successful startup , Sign in pod perform kubectl If the cluster information can be viewed, the access is successful .
边栏推荐
- Understanding Devops from the perspective of decision makers
- Is it necessary to buy EIP? Price analysis of EIP
- 2022-2028 global aircraft wireless intercom system industry research and trend analysis report
- Ligature in font design
- JMeter script FAQs
- Which domestic cloud desktop server is good? What are the security guarantees for cloud desktop servers?
- 2022-2028 global marine clutch industry research and trend analysis report
- 2022-2028 Global Industry Survey and trend analysis report on portable pressure monitors for wards
- More than 10 million Android users installed a fraud app and doubled the number of blackmail attacks in the UK | global network security hotspot
- Shopee Clickhouse cold and hot data separation storage architecture and Practice
猜你喜欢

2022-2028 global marine clutch industry research and trend analysis report

UI automation based on Selenium
![[51nod] 2653 section XOR](/img/2d/cb4bf4e14939ce432cac6d35b6a41b.jpg)
[51nod] 2653 section XOR
![[51nod] 3047 displacement operation](/img/cb/9380337adbc09c54a5b984cab7d3b8.jpg)
[51nod] 3047 displacement operation

2022-2028 global indoor pressure monitor and environmental monitor industry research and trend analysis report

2022-2028 global tungsten copper alloy industry research and trend analysis report
![[summary of interview questions] zj5](/img/d8/ece82f8b2479adb948ba706f6f5039.jpg)
[summary of interview questions] zj5
![[51nod] 3216 Awards](/img/94/fdb32434d1343040d711c76568b281.jpg)
[51nod] 3216 Awards
![[51nod] 3395 n-bit gray code](/img/b5/2c072a11601de82cb92ade94672ecd.jpg)
[51nod] 3395 n-bit gray code
![[51nod] 2106 an odd number times](/img/af/59b441420aa4f12fd50f5062a83fae.jpg)
[51nod] 2106 an odd number times
随机推荐
How to build a shopping website? What problems should be paid attention to in the construction of shopping websites?
Grpc: how to reasonably manage log configuration?
Is AI face detection and face recognition a concept? What's the difference?
How does the fortress machine connect to the server? Which is easy to use, fortress machine or firewall?
Tencent cloud CIF engineering effectiveness summit was successfully opened, and coding released a series of new products
Is your posture correct—— A detailed discussion on horizontal sub database and sub table
Sinclair radio stopped broadcasting many TV stations, suspected of being attacked by blackmail software
The 2021 Tencent digital ecology conference is coming
Tencent cloud launched its new 100g+ cloud server product!! Expect more than 400g+ in the future!
How to set up a cloud desktop server? Is there a charge for cloud desktop server setup?
Velocitytracker use
2022-2028 global marine wet exhaust hose industry research and trend analysis report
I have a server. What can I do?
Which domestic cloud desktop server is good? What are the security guarantees for cloud desktop servers?
Hunan data security governance Summit Forum was held, and Tencent built the best practice of government enterprise data security
What does cloud desktop mean? What are the characteristics of cloud desktop?
Why do cloud desktops use rack servers? Why choose cloud desktop?
What is the edge calculator force? What about the edge calculator?
Is it necessary to buy EIP? Price analysis of EIP
How to design a hybrid system