Skip to content

Commit 4d69d15

Browse files
Merge branch 'cncamp:master' into master
2 parents 39a42c5 + 5cf8bfa commit 4d69d15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+856
-120
lines changed

module10/loki-stack/readme.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cd loki-stack
2020
```
2121
### replace all `rbac.authorization.k8s.io/v1beta1` with `rbac.authorization.k8s.io/v1` by
2222
```
23-
sed s#rbac.authorization.k8s.io/v1beta1#rbac.authorization.k8s.io/v1#g *.yaml
23+
sed -i s#rbac.authorization.k8s.io/v1beta1#rbac.authorization.k8s.io/v1#g *.yaml
2424
```
2525
### install loki locally
2626
```

module11/drain-node/drain.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ kubectl uncordon
99
```
1010

1111
```
12-
curl -v -H 'Content-type: application/json' --key admin.key --cert admin.crt https://192.168.34.2:6443/api/v1/namespaces/default/pods/nginx-deployment-9b44bf4b5-x4xc4/eviction -d @eviction.json
12+
curl -v -H 'Content-type: application/json' --key client.key --cert client.crt https://192.168.34.2:6443/api/v1/namespaces/default/pods/nginx-deployment-6799fc88d8-ds499/eviction -d @eviction.json
1313
1414
{
1515
"apiVersion": "policy/v1",
1616
"kind": "Eviction",
1717
"metadata": {
18-
"name": "nginx-deployment-9b44bf4b5-x4xc4",
18+
"name": "nginx-deployment-6799fc88d8-ds499",
1919
"namespace": "default"
2020
}
2121
}

module11/drain-node/pdb.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: PodDisruptionBudget
33
metadata:
44
name: nginx-deployment
55
spec:
6-
minAvailable: 0
6+
minAvailable: 1
77
selector:
88
matchLabels:
99
app: nginx

module11/hpa/readme.MD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
```
2-
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
2+
kubectl create -f php-apache.yaml
3+
kubectl create -f hpav2.yaml
4+
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
5+
watch kubectl top pods
36
```

module11/operator/kubebuilder.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
### create a kubebuilder project, it requires an empty folder
2+
```
3+
kubebuilder init --domain cncamp.io
4+
```
5+
6+
### check project layout
7+
```
8+
cat PROJECT
9+
domain: cncamp.io
10+
layout:
11+
- go.kubebuilder.io/v3
12+
projectName: mysts
13+
repo: github.com/cncamp/demo-operator
14+
version: "3"
15+
```
16+
### create API, create resource[Y], create controller[Y]
17+
```
18+
kubebuilder create api --group apps --version v1beta1 --kind MyDaemonset
19+
```
20+
### open project by IDE and edit api/v1alpha1/simplestatefulset_types.go
21+
```
22+
// MyDaemonsetSpec defines the desired state of MyDaemonset
23+
type MyDaemonsetSpec struct {
24+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
25+
// Important: Run "make" to regenerate code after modifying this file
26+
27+
// Foo is an example field of MyDaemonset. Edit mydaemonset_types.go to remove/update
28+
Image string `json:"image,omitempty"`
29+
}
30+
31+
// MyDaemonsetStatus defines the observed state of MyDaemonset
32+
type MyDaemonsetStatus struct {
33+
AvaiableReplicas int `json:"avaiableReplicas,omitempty"`
34+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
35+
// Important: Run "make" to regenerate code after modifying this file
36+
}
37+
```
38+
### check Makefile
39+
```
40+
Build targets:
41+
### create code skeletion
42+
manifests: generate crd
43+
generate: generate api functions, like deepCopy
44+
45+
### generate crd and install
46+
run: Run a controller from your host.
47+
install: Install CRDs into the K8s cluster specified in ~/.kube/config.
48+
49+
### docker build and deploy
50+
docker-build: Build docker image with the manager.
51+
docker-push: Push docker image with the manager.
52+
deploy: Deploy controller to the K8s cluster specified in ~/.kube/config.
53+
54+
```
55+
### generate crd
56+
```
57+
make manifests
58+
```
59+
### build & install
60+
```
61+
make build
62+
make docker-build
63+
make docker-push
64+
make deploy
65+
```
66+
## enable webhooks
67+
### install cert-manager
68+
```
69+
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.6.1/cert-manager.yaml
70+
```
71+
### create webhooks
72+
```
73+
kubebuilder create webhook --group apps --version v1beta1 --kind MyDaemonset --defaulting --programmatic-validation
74+
```
75+
### change code
76+
### enable webhook in
77+
```
78+
config/default/kustomization.yaml
79+
```
80+
### redeploy
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: centos-qos
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: centos
10+
template:
11+
metadata:
12+
labels:
13+
app: centos
14+
spec:
15+
containers:
16+
- command:
17+
- tail
18+
- -f
19+
- /dev/null
20+
image: centos
21+
name: centos
22+
resources:
23+
requests:
24+
cpu: 250m
25+
memory: 1Gi
26+
limits:
27+
cpu: 250m
28+
memory: 1Gi
29+
env:
30+
- name: SYSTEM_NAMESPACE_ENV
31+
valueFrom:
32+
fieldRef:
33+
fieldPath: metadata.namespace
34+
- name: PODIP
35+
valueFrom:
36+
fieldRef:
37+
fieldPath: status.podIP
38+
- name: CPU_LIMIT
39+
valueFrom:
40+
resourceFieldRef:
41+
containerName: centos
42+
resource: limits.cpu
43+
divisor: 1m

module11/vpa/readme.MD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,24 @@
33
git clone https://github.com/kubernetes/autoscaler.git
44
```
55
### install vpa
6+
```
67
cd vertical-pod-autoscaler
78
./hack/vpa-up.sh
9+
```
10+
### test vpa
11+
```
12+
kubectl apply -f vpa.yaml
13+
```
14+
### recommmender run once per min, updater run once per min
15+
### check updater parameter for rate limit config
16+
### updater flows
17+
```
18+
1. get all pods->
19+
2. get live pods->
20+
3. get pods managed by vpa && evictable ->
21+
4. add to updater queue->
22+
5. if (within recommend range && no oom) || (oom but resourcediff==0) -->no update
23+
else pods enqueue with priority->
24+
6. sort by priority ->
25+
7. kill with ratelimit configured in command line parameter
26+
```

module12/envoy/envoy-deploy.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
run: envoy
6+
name: envoy
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
run: envoy
12+
template:
13+
metadata:
14+
labels:
15+
run: envoy
16+
spec:
17+
containers:
18+
- image: envoyproxy/envoy-dev
19+
name: envoy
20+
volumeMounts:
21+
- name: envoy-config
22+
mountPath: "/etc/envoy"
23+
readOnly: true
24+
volumes:
25+
- name: envoy-config
26+
configMap:
27+
name: envoy-config

module12/envoy/envoy.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
admin:
2+
address:
3+
socket_address: { address: 127.0.0.1, port_value: 9901 }
4+
5+
static_resources:
6+
listeners:
7+
- name: listener_0
8+
address:
9+
socket_address: { address: 0.0.0.0, port_value: 10000 }
10+
filter_chains:
11+
- filters:
12+
- name: envoy.filters.network.http_connection_manager
13+
typed_config:
14+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
15+
stat_prefix: ingress_http
16+
codec_type: AUTO
17+
route_config:
18+
name: local_route
19+
virtual_hosts:
20+
- name: local_service
21+
domains: ["*"]
22+
routes:
23+
- match: { prefix: "/" }
24+
route: { cluster: some_service }
25+
http_filters:
26+
- name: envoy.filters.http.router
27+
clusters:
28+
- name: some_service
29+
connect_timeout: 0.25s
30+
type: LOGICAL_DNS
31+
lb_policy: ROUND_ROBIN
32+
load_assignment:
33+
cluster_name: some_service
34+
endpoints:
35+
- lb_endpoints:
36+
- endpoint:
37+
address:
38+
socket_address:
39+
address: simple
40+
port_value: 80

module12/envoy/readme.MD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### deploy simple
2+
```
3+
kubectl create -f simple.yaml
4+
```
5+
### deploy envoy
6+
```
7+
kubectl create configmap envoy-config --from-file=envoy.yaml
8+
kubectl create -f envoy-deploy.yaml
9+
```

0 commit comments

Comments
 (0)