Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mfanjie committed Dec 7, 2021
1 parent cbfcad8 commit f106c5a
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 4 deletions.
4 changes: 2 additions & 2 deletions module11/drain-node/drain.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ kubectl uncordon
```

```
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
curl -v -H 'Content-type: application/json' --key client.key --cert client.crt https://192.168.34.2:6443/api/v1/namespaces/default/pods/httpserver-5b5fc75b98-rc2kf/eviction -d @eviction.json
{
"apiVersion": "policy/v1",
"kind": "Eviction",
"metadata": {
"name": "nginx-deployment-9b44bf4b5-x4xc4",
"name": "httpserver-5b5fc75b98-rc2kf",
"namespace": "default"
}
}
Expand Down
2 changes: 1 addition & 1 deletion module11/drain-node/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PodDisruptionBudget
metadata:
name: nginx-deployment
spec:
minAvailable: 0
minAvailable: 1
selector:
matchLabels:
app: nginx
5 changes: 4 additions & 1 deletion module11/hpa/readme.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
```
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
kubectl create -f php-apache.yaml
kubectl create -f hpav2.yaml
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"
watch kubectl top pods
```
81 changes: 81 additions & 0 deletions module11/operator/kubebuilder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
### create a kubebuilder project, it requires an empty folder
```
kubebuilder init --domain cncamp.io
```

### check project layout
```
cat PROJECT
domain: cncamp.io
layout:
- go.kubebuilder.io/v3
projectName: mysts
repo: github.com/cncamp/mysts
version: "3"
```
### create API, create resource[Y], create controller[Y]
```
kubebuilder create api --group apps --version v1alpha1 --kind SimpleStatefulset
```
### open project by IDE and edit api/v1alpha1/simplestatefulset_types.go
```
// SimpleStatefulsetSpec defines the desired state of SimpleStatefulset
type SimpleStatefulsetSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Foo is an example field of SimpleStatefulset. Edit simplestatefulset_types.go to remove/update
Image string `json:"image,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
}
// SimpleStatefulsetStatus defines the observed state of SimpleStatefulset
type SimpleStatefulsetStatus struct {
AvailableReplicas string `json:"availableReplicas,omitempty"`
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}
```
### check Makefile
```
Build targets:
### create code skeletion
manifests: generate crd
generate: generate api functions, like deepCopy
### generate crd and install
run: Run a controller from your host.
install: Install CRDs into the K8s cluster specified in ~/.kube/config.
### docker build and deploy
docker-build: Build docker image with the manager.
docker-push: Push docker image with the manager.
deploy: Deploy controller to the K8s cluster specified in ~/.kube/config.
```
### generate crd
```
make manifests
```
### build & install
```
make build
make docker-build
make docker-push
make deploy
```
## enable webhooks
### install cert-manager
```
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.6.1/cert-manager.yaml
```
### create webhooks
```
kubebuilder create webhook --group apps --version v1alpha1 --kind SimpleStatefulset --defaulting --programmatic-validation
```
### change code
### enable webhook in
```
config/default/kustomization.yaml
```
### redeploy
43 changes: 43 additions & 0 deletions module11/qos-pods/deployment-min-ready.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: centos-qos
spec:
replicas: 1
selector:
matchLabels:
app: centos
template:
metadata:
labels:
app: centos
spec:
containers:
- command:
- tail
- -f
- /dev/null
image: centos
name: centos
resources:
requests:
cpu: 250m
memory: 1Gi
limits:
cpu: 250m
memory: 1Gi
env:
- name: SYSTEM_NAMESPACE_ENV
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: PODIP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: CPU_LIMIT
valueFrom:
resourceFieldRef:
containerName: centos
resource: limits.cpu
divisor: 1m
19 changes: 19 additions & 0 deletions module11/vpa/readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@
git clone https://github.com/kubernetes/autoscaler.git
```
### install vpa
```
cd vertical-pod-autoscaler
./hack/vpa-up.sh
```
### test vpa
```
kubectl apply -f vpa.yaml
```
### recommmender run once per min, updater run once per min
### check updater parameter for rate limit config
### updater flows
```
1. get all pods->
2. get live pods->
3. get pods managed by vpa->
4. add to updater queue->
5. if (within recommend range && no oom) || (oom but resourcediff==0) -->no update
else pods enqueue with priority->
6. sort by priority ->
7. kill with ratelimit configured in command line parameter
```

0 comments on commit f106c5a

Please sign in to comment.