Skip to content

Commit 022ea92

Browse files
wip: added more details
1 parent a8d5405 commit 022ea92

File tree

1 file changed

+64
-11
lines changed

1 file changed

+64
-11
lines changed

Kubeconfig.md

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,23 @@ if client want then it need private key and client certificate
66

77
## How to access the kubeconfig file on our machine
88

9-
```bash
10-
rahulxf@Rahuls-MacBook-Air-3 ~ % cd $HOME/.kube/ 
9+
```go
10+
rahulxf@Rahuls-MacBook-Air-3 ~ % cd $HOME/.kube<---
1111

1212
rahulxf@Rahuls-MacBook-Air-3 .kube % ls -l
1313
total 160
1414
drwxr-x---@ 4 rahulxf  staff    128 Jan 17 22:46 cache
15-
-rw-------@ 1 rahulxf  staff  31948 Feb 17 10:48 config
15+
-rw-------@ 1 rahulxf  staff  31948 Feb 17 10:48 config <--- kubeconfig file
1616
-rw-r--r--  1 rahulxf  staff   7973 Feb  4 16:01 karmada-apiserver.config
1717
-rw-------  1 rahulxf  staff  13415 Feb 11 19:28 karmada.config
1818
-rw-r--r--  1 rahulxf  staff      4 Feb 17 10:43 kubectx
1919
drwxr-xr-x  4 rahulxf  staff    128 Feb 17 10:48 kubens
2020
-rw-r--r--  1 rahulxf  staff  16652 Feb  2 22:01 members.config
21-
22-
rahulxf@Rahuls-MacBook-Air-3 .kube %
23-
24-
rahulxf@Rahuls-MacBook-Air-3 .kube % vim config
25-
rahulxf@Rahuls-MacBook-Air-3 .kube % vim config
2621
```
2722

2823
* config is the kubeconfig file
2924

30-
```
25+
```rs
3126
apiVersion: v1
3227
clusters:
3328
- cluster:
@@ -78,7 +73,14 @@ client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURLVENDQWhHZ0F
7873
client-key-data: LS0tLS
7974
```
8075

76+
Flow diagram
77+
----
78+
79+
<img width="929" alt="shapes at 25-02-20 12 40 47" src="https://github.com/user-attachments/assets/fee09087-1fce-4324-bf42-44f01e0464ad" />
80+
81+
8182
How to add users
83+
----
8284

8385
```
8486
$ kubectl config set-credentials devuser --client-certificate du.crt --client-key du.key
@@ -87,6 +89,7 @@ User "devuser" set.
8789
```
8890

8991
You also need to map it , i mean you need to add context for this user for the cluster
92+
---
9093

9194
```
9295
$ kubectl config set-context --cluster kind-kind --user devuser
@@ -102,6 +105,7 @@ Context "devuser-kind" created
102105
```
103106

104107
If you want to check which context we are using
108+
---
105109

106110
`$ kubectl config current-context`
107111

@@ -121,7 +125,8 @@ $ export KUBECONFIG=~/.kube/config:~/.kube/karmada.config:~/.kube/karmada-apiser
121125

122126
<img width="1120" alt="Screenshot 2025-02-18 at 11 21 48 PM" src="https://github.com/user-attachments/assets/d1d742bf-d308-42a8-bcf6-41b4d5c881da" />
123127

124-
To authenticate the user to kubernetes cluster we will do client certificate management
128+
To authenticate the user to Kubernetes cluster we will do client certificate management
129+
---
125130

126131
docker ps (get the id )
127132
docker exec -it <id> bash
@@ -131,7 +136,7 @@ ls -l (you will see the key, csr and other files )
131136

132137
* So for creating private key and csr key you can run this command to generate
133138

134-
<img width="1179" alt="shapes at 25-02-20 00 13 41" src="https://github.com/user-attachments/assets/2aedf2d0-8b1b-4a23-9ce0-c815020ec5fa" />
139+
<img width="1199" alt="shapes at 25-02-20 12 39 00" src="https://github.com/user-attachments/assets/99159373-2e30-4568-85a3-d36f1536d9a9" />
135140

136141
Generate new ssl key:
137142
-----
@@ -182,9 +187,57 @@ $ kubectx
182187
```
183188
<img width="1094" alt="Screenshot 2025-02-19 at 1 10 23 AM" src="https://github.com/user-attachments/assets/093537f4-76b7-4f11-890e-77781eefa5cd" />
184189

190+
185191
* allow namespaces
186192
<img width="1310" alt="Screenshot 2025-02-19 at 1 17 41 AM" src="https://github.com/user-attachments/assets/b9e2ca7c-ac1c-4b7c-9384-4ec96a951f15" />
187193

188194

189195
* allow pods
190196
<img width="1310" alt="Screenshot 2025-02-19 at 1 23 04 AM" src="https://github.com/user-attachments/assets/9967a9df-bac0-42d9-9b3a-d177e764b2b5" />
197+
198+
Certificate Singning Request
199+
----
200+
* Creating the certificate singning request with the k8s ca.crt key
201+
<img width="1337" alt="Screenshot 2025-02-19 at 1 31 19 AM" src="https://github.com/user-attachments/assets/2b8a8983-e7b8-4731-861c-4664d129f649" />
202+
203+
* To put into our csr yaml file we need to encode the key
204+
<img width="1337" alt="Screenshot 2025-02-19 at 1 34 14 AM" src="https://github.com/user-attachments/assets/d602c7c0-b2d1-421e-b8ee-962f2742e046" />
205+
206+
```yaml
207+
// csr.yaml
208+
apiVersion: certificates.k8s.io/v1
209+
kind: CertificateSigningRequest
210+
metadata:
211+
name: rahulxf
212+
spec:
213+
groups:
214+
- developers
215+
request: |
216+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS....
217+
signerName: kubernetes.io/kube-apiserver-client
218+
usages:
219+
- client auth
220+
```
221+
222+
And then create it using kubectl command
223+
224+
```bash
225+
$ kubectl create -f csr. yaml
226+
certificatesigningrequest.certificates.k8s.io/rahulxf_created
227+
228+
# Get your certificate
229+
$ kubectl get csr
230+
231+
# Approve your certificate
232+
# rahulxf == name
233+
$ kubectl certificate approve rahulxf
234+
235+
# Look for the certificate details
236+
$ kubectl describe csr rahulxf
237+
```
238+
239+
<img width="1337" alt="Screenshot 2025-02-19 at 1 44 04 AM" src="https://github.com/user-attachments/assets/477297d6-ac7a-4db7-8b0e-f26b586b9620" />
240+
241+
<img width="1231" alt="Screenshot 2025-02-20 at 12 35 04 PM" src="https://github.com/user-attachments/assets/87e933b6-de22-44ef-9d32-3b1ad54b9f7b" />
242+
243+

0 commit comments

Comments
 (0)