forked from cncamp/101
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters