-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMisc Updates 2021
365 lines (262 loc) · 6.56 KB
/
Misc Updates 2021
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
Misc Updates 2021
----------------
FROM Ubuntu
RUN apt-get update
RUN apt-get install python
RUN pip install flask
RUN pip install flask-msysql
COPY . /opt/souce-code
EXPOSE 8080
ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run
> docker build Dockerfile -t mmumshad/my-custom-app
To view layer build of an image
> docker history mmumshad/simple-webapp
--- AAA on K8S
Auth mechanisms
- Static Password File
- Static Token File
- certificates
- Identity Services
--- KubeConfig
$HOME/.kube/config by default
apiVersion: v1
kind: Config
current-context: my-kube-admin@my-kube-playground
clusers:
- name: my-kube-playground
cluster:
certificate-authority: /etc/kubernetes/pki/ca.crt
server: https://my-kube-playground:6443
contexts:
- name: my-kube-admin@my-kube-playground
context:
cluster: my-kube-playground
user: my-kube-admin
namespace: finance
users:
- name: my-kube-admin
user:
client-certificate: /etc/kubernetes/pki/users/admin.crt
client-key: /etc/kubernetes/pki/users/admin.key
> kubectl config view
> kubectl config view --kubeconfig=my-custom-config
> kubectl config use-context prod-user@production
> kubectl config -h
RBAC
-----
developer-role.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: developer
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["list","get","create","update","delete"]
- apiGroups: [""]
resources: ["configMap"]
verbs: ["create"]
> kubectl create -f developer-role.yaml
Now create the role binding
devuser-developer-binding.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: devuser-developer-binding
subjects:
- kind: User
name: dev-user
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: developer
apiGroup: rbac.authorization.k8s.io
> kubectl create -f devuser-developer-binding.yaml
check access
> kubectl auth can-i create deployments
yes
> kubectl auth can-i delete nodes
no
> kubectl auth can-i create deployments --as dev-user
no
> kubectl auth can-i create pods --as dev-user
yes
> kubectl auth can-i create pods --as dev-user --namespace test
no
Cluster Roles
--------
To view an exhaustive list of namespaced and non namespaced objects :
> kubectl api-resources --namespaced=true
> kubectl api-resources --namespaced=false
cluster-admin-role.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cluster-administrator
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list","get","create","delete"]
> kubectl create -f cluster-admin-role.yaml
Now we need to link the role to the user
cluster-admin-role-binding.yaml
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: cluster-admin-role-binding
subjects:
- kind: User
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: cluster-administrator
apiGroup: rbac.authorization.k8s.io
> kubectl create -f cluster-admin-role-binding.yaml
Admission Controllers
----------
View enabled admission controllers
> kube-apiserver -h | grep enable-admission-plugins
> kubectl exec kube-apiserver-controlplane -n kube-system -- kube-apiserver -h | grep enable-admission-plugins
To add an admission controler
edit : /etc/kubernetes/manifest/kube-apiserver.yaml and modify the line with - --enable-admission-plugins
Since the kube-apiserver is running as pod you can check the process to see enabled and disabled plugins.
ps -ef | grep kube-apiserver | grep admission-plugins
Validating and Mutating Admission Controller
--------
There are two types of admission controllers
- Validating admission controller
- Mutating admission controllers
Mutating admission controllers are always invoked before validating admission controllers
Custom admission controllers can be created using webhook
1- Deploy a webhook server in go or python
2- Configuring Admission Webhook
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: "pod-policy.example.com"
webhook:
- name: "pod-policy.example.com"
clientConfig:
url: "https://external-server.example.com"
service:
namespace: "webhook-namespace"
name: "webhook-service"
ca-bundle: "Ci0tLS0tQk...tLS0K"
rules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE"]
resources: ["pods"]
scope: "Namespaced"
API Versions:
--------------
kubectl convert is a plugin that must be installed, not installed by default
> curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert
> kubectl convert -f <old-file> --output-version <new-api>
> kubectl-convert -f nginx.yaml --output-version apps/v1
Custom Resource Definition ( CRD )
----------------------------
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: flighttickets.flights.com
spec:
scope: Namespaced
groups: flights.com
names:
kind: FlightTicket
singular: flightticket
plural: flighttickets
shortnames:
- ft
version:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
from:
type: string
to:
type: string
number:
type: integer
minimum: 1
maximum: 10
> kubectl create -f
Customer Controllers
-------------------
operatorhub.io
Deployment Strategy - Blue Green
---
Recreate
Rolling update
Blue Green : New version (green) is deployed alongside with old version (blue)
Canary : New version is deployed and part of user traffic is sent to it
myapp-primary.yml
----
apiVersion:
kind:
metadata:
name: myapp-primary
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
version: v1
app: front-end
spec:
containers:
- name: app-container
image: myapp-image:1.0
replicas: 5
selector:
matchLabels:
app: front-end
service-definition.yaml
---
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: front-end
myapp-canary.yml
----
apiVersion:
kind:
metadata:
name: myapp-canary
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
version: v2
app: front-end
spec:
containers:
- name: app-container
image: myapp-image:2.0
replicas: 1
selector:
matchLabels:
app: front-end