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
fmeng
committed
Jun 13, 2020
1 parent
8dcb689
commit 3eb9b91
Showing
6 changed files
with
286 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# setup local env | ||
https://minikube.sigs.k8s.io/docs/ | ||
## install hyperkit https://minikube.sigs.k8s.io/docs/drivers/hyperkit/ | ||
For MacOS | ||
``` | ||
$ git clone https://github.com/moby/hyperkit.git | ||
$ make | ||
$ cp ./build/hyperkit //usr/local/bin/hyperkit | ||
``` | ||
## download minikube https://github.com/kubernetes/minikube/releases | ||
For MacOS | ||
``` | ||
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 | ||
$ sudo install minikube-darwin-amd64 /usr/local/bin/minikube | ||
``` | ||
## config minikube | ||
``` | ||
$ minikube config set driver hyperkit | ||
``` | ||
## start minikube | ||
``` | ||
$ minikube start \ | ||
--cpus=8 \ | ||
--v=4 \ | ||
--memory=8192 \ | ||
--network-plugin=cni \ | ||
--enable-default-cni \ | ||
--bootstrapper=kubeadm \ | ||
--kubernetes-version v1.18.3 \ | ||
--image-mirror-country=cn \ | ||
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers | ||
``` | ||
|
||
5. istio setup | ||
|
||
``` | ||
$ kubectl create ns bookinfo | ||
$ kubectl label namespace bookinfo istio-injection=enabled | ||
$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml -n bookinfo | ||
$ kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml -n bookinfo | ||
``` | ||
|
||
|
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,64 @@ | ||
|
||
# Understand Docker | ||
## overlay fs | ||
``` | ||
$ mkdir upper lower merged work | ||
$ echo "from lower" > lower/in_lower.txt | ||
$ echo "from upper" > upper/in_upper.txt | ||
$ echo "from lower" > lower/in_both.txt | ||
$ echo "from upper" > upper/in_both.txt | ||
$ sudo mount -t overlay overlay -o lowerdir=`pwd`/lower,upperdir=`pwd`/upper,workdir=`pwd`/work `pwd`/merged | ||
$ cat merged/in_both.txt | ||
``` | ||
``` | ||
$ echo 'new file' > merged/new_file | ||
$ ls -l */new_file | ||
``` | ||
``` | ||
$ rm merged/in_both.txt | ||
$ ls -l upper/in_both.txt lower/in_both.txt merged/in_both.txt | ||
``` | ||
``` | ||
$ mount -t overlay overlay -o lowerdir:/dir1:/dir2:/dir3:...:/dir25,upperdir=... | ||
``` | ||
## namespace | ||
``` | ||
$ lsns -t net | ||
$ cd /proc/25452/ns/ | ||
$ nsenter -t <pid> -n ip addr | ||
``` | ||
## cgroup | ||
``` | ||
$ cat /proc/25452/cgroup | ||
11:pids:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
10:freezer:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
9:hugetlb:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
8:perf_event:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
7:blkio:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
6:cpuset:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
5:memory:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
4:devices:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
3:cpu,cpuacct:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
2:net_cls,net_prio:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
1:name=systemd:/kubepods/besteffort/pod8d80a5f8-cb1e-4b28-ba54-393e6b363e20/a99d384f32fc7aeb8a06934e387ed9ea30992676257a61af37d705805f1dffb7 | ||
``` | ||
``` | ||
$ docker ps | ||
``` | ||
``` | ||
$ docker inspect <containerid>| grep -i cgroup | ||
"CgroupParent": "kubepods-burstable-podfc9d9da9_7d7a_4970_b306_8ee27f121de1.slice", | ||
``` | ||
``` | ||
$ cd /sys/fs/cgroup/memory/kubepods.slice/kubepods-burstable.slice | ||
``` | ||
``` | ||
$ cd kubepods-burstable-podfc9d9da9_7d7a_4970_b306_8ee27f121de1.slice | ||
``` | ||
``` | ||
$ ls | ||
$ cat memory.limit_in_bytes | ||
1073741824 | ||
``` | ||
|
||
|
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,101 @@ | ||
# Understand Microsoft | ||
## microsoft demo, run nginx as webserver | ||
``` | ||
$ kubectl run --image=nginx nginx | ||
``` | ||
## show running pod | ||
``` | ||
$ kubectl get po --show-labels -owide -w | ||
``` | ||
## expose svc | ||
``` | ||
$ kubectl expose deploy nginx --selector run=nginx --port=80 --type=NodePort | ||
``` | ||
## check svc detail | ||
``` | ||
$ kubectl get svc | ||
``` | ||
## check nodeip | ||
``` | ||
$ minikube ssh | ||
$ ifconfig eth1 | ||
``` | ||
## access service | ||
``` | ||
$ curl <nodeip>:<nodeport> | ||
``` | ||
## run envoy | ||
``` | ||
$ kubectl create configmap envoy-config --from-file=envoy.yaml | ||
$ kubectl create -f envoy-deploy.yaml | ||
$ kubectl expose deploy envoy --selector run=envoy --port=10000 --type=NodePort | ||
``` | ||
## access service | ||
``` | ||
$ curl <nodeip>:<nodeport> | ||
``` | ||
## scale up/down/failover | ||
``` | ||
$ kubectl scale deploy <deployment-name> --replicas=<n> | ||
``` | ||
# configmap | ||
``` | ||
cat game.properties | ||
#configmap from file | ||
kubectl create configmap game-config --from-file=game.properties | ||
kubectl create configmap game-env-config --from-env-file=game.properties | ||
kubectl get configmap -oyaml game-config | ||
``` | ||
## configmap from literal | ||
``` | ||
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm | ||
#downward api pod | ||
kubectl create -f downward-api-pod.yaml | ||
kubectl get po downward-api-pod | ||
kubectl logs -f downward-api-pod | ||
``` | ||
# volume | ||
``` | ||
kubectl create -f configmap-volume-pod.yaml | ||
kubectl get po | ||
kubectl logs -f configmap-volume-pod | ||
``` | ||
# readiness probe | ||
``` | ||
kubectl create -f centos-readiness.yaml | ||
``` | ||
# multiple container pods | ||
## get object by columns | ||
``` | ||
kubectl get svc -o=custom-columns=NAME:.metadata.name,CREATED:'.metadata.annotations' | ||
``` | ||
# Operator | ||
## kubebuilder | ||
``` | ||
$ kubebuilder init --domain example.com | ||
$ kubebuilder create api --group infra --version v1 --kind WebService | ||
$ make install | ||
``` | ||
## operator sdk | ||
## create new project | ||
``` | ||
operator-sdk new memorycache-operator | ||
``` | ||
## add types | ||
|
||
``` | ||
cd memorycache-operator | ||
operator-sdk add api --api-version=cache.example.com/v1alpha1 --kind=Memcached | ||
``` | ||
## modify types and generate new code | ||
|
||
``` | ||
operator-sdk generate k8s | ||
operator-sdk generate openapi | ||
``` | ||
## operator helm | ||
``` | ||
operator-sdk new nginx-operator --type=helm --kind=Nginx --api-version=web.example.com/v1alpha1 | ||
operator-sdk add crd --api-version=web.example.com/v1alpha1 --kind=Envoy --update-watches=true | ||
``` |
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,30 @@ | ||
# Setup Istio | ||
## Download istio release | ||
``` | ||
$ curl -L https://istio.io/downloadIstio | sh - | ||
``` | ||
## Move to the Istio package directory | ||
``` | ||
$ cd istio-1.6.2 | ||
``` | ||
## Add istioctl to path | ||
``` | ||
$ export PATH=$PWD/bin:$PATH | ||
``` | ||
## Install Istio | ||
``` | ||
$ istioctl install --set profile=demo | ||
``` | ||
# Manage Istio | ||
## Enable access log | ||
``` | ||
$ istioctl manifest apply --set values.global.proxy.accessLogFile="/dev/stdout" | ||
``` | ||
## Enable mts | ||
``` | ||
$ istioctl manifest apply --set values.global.mtls.enabled=true --set values.global.controlPlaneSecurityEnabled=true | ||
``` | ||
## Enable tracing | ||
``` | ||
$ istioctl manifest apply --set values.tracing.enabled=disable --set values.tracing.provider=zipkin | ||
``` |
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 @@ | ||
# Understand Istio | ||
## Create bookinfo app sample | ||
``` | ||
$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml | ||
``` | ||
|
||
## create dr | ||
``` | ||
$ kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml | ||
``` | ||
## vs all v1 | ||
``` | ||
$ kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml | ||
``` | ||
## header based vs | ||
``` | ||
$ kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml | ||
``` | ||
## delete vs | ||
``` | ||
$ kubectl delete -f samples/bookinfo/networking/virtual-service-all-v1.yaml | ||
``` | ||
## add fix delay to rating | ||
``` | ||
$ kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml | ||
``` | ||
## proxy-config | ||
``` | ||
$ istioctl pc | ||
``` | ||
## proxy-status | ||
``` | ||
$ istioctl ps | ||
``` | ||
## check authn status | ||
``` | ||
$ istioctl authn tls-check details-v1-74f858558f-qqg99 | ||
``` | ||
## rate limit | ||
``` | ||
$ kubectl apply -f samples/bookinfo/policy/mixer-rule-productpage-ratelimit.yaml | ||
``` | ||
|
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,10 +1,10 @@ | ||
minikube start \ | ||
--cpus 4 \ | ||
--memory 4096 \ | ||
--cpus=8 \ | ||
--v=4 \ | ||
--memory=8192 \ | ||
--network-plugin=cni \ | ||
--enable-default-cni \ | ||
--bootstrapper=kubeadm \ | ||
--kubernetes-version v1.15.4 \ | ||
--kubernetes-version v1.18.3 \ | ||
--image-mirror-country=cn \ | ||
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers | ||
|
||
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers |