├── README.md ├── helm ├── override.yaml └── mychart │ ├── Chart.yaml │ ├── values.yaml │ ├── templates │ └── configmap.yaml │ └── .helmignore ├── helm-rbac ├── sa.yaml └── clusterrolebinding.yaml ├── service-account ├── sa.yaml ├── pod.yaml ├── clusterrolebinding.yaml └── Makefile ├── resource ├── image │ ├── Dockerfile │ └── main.go └── resource.yaml ├── probe ├── app │ ├── go.mod │ ├── main.go │ ├── health.go │ └── go.sum ├── Makefile ├── Dockerfile └── probe-deployment.yaml ├── service ├── clusterip.yml ├── nodeport.yml └── deploy.yaml ├── nginx-ingress ├── service.yml ├── Makefile ├── ingress.yml ├── deployment.yml └── README.md ├── neg ├── ingress.yaml ├── svc.yaml └── deploy.yaml ├── envoy-service-mesh ├── service-user-admin.yml ├── service-alive-admin.yml ├── service-gateway.yml ├── service-alive.yml ├── service-user.yml ├── README.md ├── Makefile ├── deployment-gateway.yml ├── deployment-user.yml ├── deployment-alive.yml └── envoy-config │ ├── sidecar-service.yaml │ └── sidecar-gateway.yaml ├── headless ├── service.yml └── deployment.yml └── client-side-lb ├── headless-svc.yml ├── client-deploy.yml └── server-deploy.yml /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Sample 2 | -- 3 | -------------------------------------------------------------------------------- /helm/override.yaml: -------------------------------------------------------------------------------- 1 | favorite: 2 | drink: tea 3 | food: rice 4 | 5 | -------------------------------------------------------------------------------- /helm-rbac/sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: tiller 5 | namespace: helm 6 | -------------------------------------------------------------------------------- /service-account/sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: sample-serviceaccount 5 | namespace: default 6 | -------------------------------------------------------------------------------- /helm/mychart/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | appVersion: "1.0" 3 | description: A Helm chart for Kubernetes 4 | name: mychart 5 | version: 0.1.0 6 | -------------------------------------------------------------------------------- /helm/mychart/values.yaml: -------------------------------------------------------------------------------- 1 | favorite: 2 | drink: coffee 3 | food: pizza 4 | pizzaToppings: 5 | - mushrooms 6 | - cheese 7 | - peppers 8 | - onions 9 | -------------------------------------------------------------------------------- /resource/image/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:alpine 2 | 3 | WORKDIR /app 4 | COPY main.go /app 5 | RUN go build -o main . 6 | 7 | EXPOSE 8000 8 | 9 | CMD ["./main"] 10 | -------------------------------------------------------------------------------- /probe/app/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jun06t/kubernetes-sample/probe 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/jun06t/grpc-sample v0.0.0-20200116205135-9fd34cc7dcb3 7 | google.golang.org/grpc v1.56.3 8 | ) 9 | -------------------------------------------------------------------------------- /probe/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build push 2 | 3 | REGISTRY_DOMAIN := jun06t 4 | 5 | build: 6 | docker build -f Dockerfile -t ${REGISTRY_DOMAIN}/probe:latest . 7 | 8 | push: 9 | docker push ${REGISTRY_DOMAIN}/probe 10 | 11 | -------------------------------------------------------------------------------- /service/clusterip.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | type: ClusterIP 7 | ports: 8 | - port: 3000 9 | protocol: TCP 10 | targetPort: 80 11 | selector: 12 | name: nginx 13 | -------------------------------------------------------------------------------- /service/nodeport.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | type: NodePort 7 | ports: 8 | - port: 3000 9 | protocol: TCP 10 | targetPort: 80 11 | selector: 12 | name: nginx 13 | -------------------------------------------------------------------------------- /nginx-ingress/service.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: hello-world-svc 5 | spec: 6 | type: NodePort 7 | ports: 8 | - port: 8080 9 | protocol: TCP 10 | targetPort: 80 11 | selector: 12 | app: hello-world 13 | -------------------------------------------------------------------------------- /neg/ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1beta1 2 | kind: Ingress 3 | metadata: 4 | name: neg-ingress 5 | spec: 6 | rules: 7 | - http: 8 | paths: 9 | - path: /* 10 | backend: 11 | serviceName: neg-svc 12 | servicePort: 80 13 | -------------------------------------------------------------------------------- /neg/svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: neg-svc 5 | annotations: 6 | cloud.google.com/neg: '{"ingress": true}' 7 | spec: 8 | type: ClusterIP 9 | selector: 10 | app: sample 11 | ports: 12 | - port: 80 13 | protocol: TCP 14 | targetPort: 8080 -------------------------------------------------------------------------------- /envoy-service-mesh/service-user-admin.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: user-admin-svc 5 | spec: 6 | type: NodePort 7 | ports: 8 | - name: admin 9 | port: 3001 10 | protocol: TCP 11 | targetPort: 10001 12 | selector: 13 | app: user-service 14 | 15 | -------------------------------------------------------------------------------- /envoy-service-mesh/service-alive-admin.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: alive-admin-svc 5 | spec: 6 | type: NodePort 7 | ports: 8 | - name: admin 9 | port: 3001 10 | protocol: TCP 11 | targetPort: 10001 12 | selector: 13 | app: alive-service 14 | 15 | -------------------------------------------------------------------------------- /service-account/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: sample-kubectl 5 | spec: 6 | serviceAccountName: sample-serviceaccount 7 | containers: 8 | - name: kubectl-container 9 | image: lachlanevenson/k8s-kubectl:v1.10.4 10 | command: ["sleep", "86400"] 11 | 12 | -------------------------------------------------------------------------------- /nginx-ingress/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: destroy apply 2 | 3 | apply: 4 | kubectl apply -f deployment.yml 5 | kubectl apply -f service.yml 6 | kubectl apply -f ingress.yml 7 | 8 | destroy: 9 | kubectl delete deploy hello-world-deployment 10 | kubectl delete svc hello-world-svc 11 | kubectl delete ingress nginx-ingress 12 | 13 | -------------------------------------------------------------------------------- /helm-rbac/clusterrolebinding.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | name: tiller 5 | roleRef: 6 | apiGroup: rbac.authorization.k8s.io 7 | kind: ClusterRole 8 | name: cluster-admin 9 | subjects: 10 | - kind: ServiceAccount 11 | name: tiller 12 | namespace: helm 13 | -------------------------------------------------------------------------------- /service-account/clusterrolebinding.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | name: sample-clusterrolebinding 5 | roleRef: 6 | apiGroup: rbac.authorization.k8s.io 7 | kind: ClusterRole 8 | name: view 9 | subjects: 10 | - kind: ServiceAccount 11 | name: sample-serviceaccount 12 | namespace: default 13 | -------------------------------------------------------------------------------- /envoy-service-mesh/service-gateway.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: gateway-svc 5 | spec: 6 | type: NodePort 7 | ports: 8 | - name: proxy 9 | port: 3000 10 | protocol: TCP 11 | targetPort: 10000 12 | - name: admin 13 | port: 3001 14 | protocol: TCP 15 | targetPort: 10001 16 | selector: 17 | app: gateway 18 | 19 | -------------------------------------------------------------------------------- /nginx-ingress/ingress.yml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1beta1 2 | kind: Ingress 3 | metadata: 4 | name: nginx-ingress 5 | annotations: 6 | kubernetes.io/ingress.class: "nginx" 7 | spec: 8 | rules: 9 | - host: hello-world.info 10 | http: 11 | paths: 12 | - backend: 13 | serviceName: hello-world-svc 14 | servicePort: 8080 15 | path: / 16 | -------------------------------------------------------------------------------- /service-account/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: destroy apply 2 | 3 | apply: 4 | kubectl apply -f sa.yaml 5 | kubectl apply -f clusterrolebinding.yaml 6 | kubectl apply -f pod.yaml 7 | 8 | destroy: 9 | kubectl delete po sample-kubectl 10 | kubectl delete sa sample-serviceaccount 11 | kubectl delete clusterrolebinding sample-clusterrolebinding 12 | 13 | test: 14 | kubectl exec -it sample-kubectl -- kubectl get pods 15 | -------------------------------------------------------------------------------- /headless/service.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: headless-svc 5 | spec: 6 | clusterIP: None 7 | ports: 8 | # Actually, no port is needed. 9 | # but set it because of the following bug. 10 | # https://github.com/kubernetes/kubernetes/issues/55158 11 | - name: headless 12 | port: 12345 13 | protocol: TCP 14 | targetPort: 12345 15 | selector: 16 | app: hello-world 17 | -------------------------------------------------------------------------------- /helm/mychart/templates/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: {{ .Release.Name }}-configmap 5 | data: 6 | myvalue: "Hello World" 7 | {{- with .Values.favorite }} 8 | drink: {{ .drink | quote }} 9 | food: {{ .food | quote }} 10 | {{- end }} 11 | toppings: |- 12 | {{- range $index, $topping := .Values.pizzaToppings }} 13 | {{ $index }}: {{ $topping }} 14 | {{- end }} 15 | -------------------------------------------------------------------------------- /client-side-lb/headless-svc.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: headless-svc 5 | spec: 6 | clusterIP: None 7 | ports: 8 | # Actually, no port is needed. 9 | # but set it because of the following bug. 10 | # https://github.com/kubernetes/kubernetes/issues/55158 11 | - name: headless 12 | port: 8080 13 | protocol: TCP 14 | targetPort: 8080 15 | selector: 16 | app: server 17 | -------------------------------------------------------------------------------- /envoy-service-mesh/service-alive.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: alive-svc 5 | spec: 6 | clusterIP: None 7 | ports: 8 | # Actually, no port is needed. 9 | # but set it because of the following bug. 10 | # https://github.com/kubernetes/kubernetes/issues/55158 11 | - name: headless 12 | port: 12345 13 | protocol: TCP 14 | targetPort: 12345 15 | selector: 16 | app: alive-service 17 | -------------------------------------------------------------------------------- /envoy-service-mesh/service-user.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: user-svc 5 | spec: 6 | clusterIP: None 7 | ports: 8 | # Actually, no port is needed. 9 | # but set it because of the following bug. 10 | # https://github.com/kubernetes/kubernetes/issues/55158 11 | - name: headless 12 | port: 12345 13 | protocol: TCP 14 | targetPort: 12345 15 | selector: 16 | app: user-service 17 | -------------------------------------------------------------------------------- /neg/deploy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: neg-deployment 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | app: sample 10 | template: 11 | metadata: 12 | labels: 13 | app: sample 14 | spec: 15 | containers: 16 | - name: sample 17 | image: gcr.io/google-samples/hello-app:2.0 18 | ports: 19 | - containerPort: 8080 20 | -------------------------------------------------------------------------------- /helm/mychart/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | .vscode/ 23 | -------------------------------------------------------------------------------- /service/deploy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | name: nginx 9 | replicas: 3 10 | template: 11 | metadata: 12 | labels: 13 | name: nginx 14 | spec: 15 | containers: 16 | - name: nginx-container 17 | imagePullPolicy: Always 18 | image: nginx:1.11 19 | ports: 20 | - containerPort: 80 21 | -------------------------------------------------------------------------------- /headless/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: headless-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: hello-world 9 | replicas: 2 10 | template: 11 | metadata: 12 | labels: 13 | app: hello-world 14 | spec: 15 | containers: 16 | - image: "strm/helloworld-http" 17 | imagePullPolicy: Always 18 | name: hello-world-container 19 | ports: 20 | - containerPort: 80 21 | -------------------------------------------------------------------------------- /nginx-ingress/deployment.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: hello-world-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: hello-world 9 | replicas: 3 10 | template: 11 | metadata: 12 | labels: 13 | app: hello-world 14 | spec: 15 | containers: 16 | - image: "strm/helloworld-http" 17 | imagePullPolicy: Always 18 | name: hello-world-container 19 | ports: 20 | - containerPort: 80 21 | -------------------------------------------------------------------------------- /resource/image/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "runtime" 7 | ) 8 | 9 | func main() { 10 | cpus := runtime.NumCPU() 11 | fmt.Println("CPUs:", cpus) 12 | 13 | for i := 0; i < 100; i++ { 14 | goroutine() 15 | } 16 | 17 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 18 | fmt.Fprintf(w, "hello world") 19 | }) 20 | 21 | http.ListenAndServe(":8000", nil) 22 | } 23 | 24 | func goroutine() { 25 | go func() { 26 | var counter int64 27 | for { 28 | counter++ 29 | } 30 | }() 31 | } 32 | -------------------------------------------------------------------------------- /envoy-service-mesh/README.md: -------------------------------------------------------------------------------- 1 | envoy-service-mesh 2 | -- 3 | 4 | # Quick start 5 | ## Create ConfigMap 6 | ``` 7 | make configmap 8 | ``` 9 | 10 | ## Apply each deployments and services 11 | ``` 12 | make apply 13 | ``` 14 | 15 | ## Destroy cluster 16 | ``` 17 | make destroy 18 | ``` 19 | 20 | # System Architecture 21 | ## Service Overview 22 |  23 | 24 | ## Detail 25 |  26 | -------------------------------------------------------------------------------- /probe/app/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | 7 | "google.golang.org/grpc" 8 | health "google.golang.org/grpc/health/grpc_health_v1" 9 | 10 | pb "github.com/jun06t/grpc-sample/unary/proto" 11 | ) 12 | 13 | const ( 14 | port = ":8080" 15 | ) 16 | 17 | func main() { 18 | lis, err := net.Listen("tcp", port) 19 | if err != nil { 20 | log.Fatal(err) 21 | } 22 | 23 | s := grpc.NewServer() 24 | pb.RegisterGreeterServer(s, &helloHandler{}) 25 | health.RegisterHealthServer(s, &healthHandler{}) 26 | err = s.Serve(lis) 27 | if err != nil { 28 | log.Fatal(err) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /probe/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:alpine3.10 2 | 3 | ARG USER=appuser 4 | ARG GROUP=appgroup 5 | 6 | RUN apk --no-cache add ca-certificates && \ 7 | addgroup -S ${GROUP} && adduser -S ${USER} -G ${GROUP} 8 | 9 | RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && \ 10 | wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ 11 | chmod +x /bin/grpc_health_probe 12 | 13 | WORKDIR /home/${USER} 14 | 15 | COPY --chown=${USER}:${GROUP} app/ . 16 | 17 | USER ${USER} 18 | 19 | RUN go build -o server 20 | 21 | CMD ["./server"] 22 | 23 | -------------------------------------------------------------------------------- /resource/resource.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: sample-resource 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | app: sample-app 10 | template: 11 | metadata: 12 | labels: 13 | app: sample-app 14 | spec: 15 | containers: 16 | - name: golang 17 | image: jun06t/show-cpus 18 | # env: 19 | # - name: GODEBUG 20 | # value: "scheddetail=1,schedtrace=1000" 21 | resources: 22 | requests: 23 | memory: "128Mi" 24 | cpu: "100m" 25 | limits: 26 | memory: "256Mi" 27 | cpu: "200m" 28 | 29 | -------------------------------------------------------------------------------- /probe/probe-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: probe 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: probe 9 | replicas: 2 10 | template: 11 | metadata: 12 | labels: 13 | app: probe 14 | spec: 15 | containers: 16 | - name: probe 17 | image: "jun06t/probe" 18 | ports: 19 | - containerPort: 8080 20 | readinessProbe: 21 | exec: 22 | command: ["/bin/grpc_health_probe", "-addr=:8080"] 23 | initialDelaySeconds: 5 24 | livenessProbe: 25 | exec: 26 | command: ["/bin/grpc_health_probe", "-addr=:8080"] 27 | initialDelaySeconds: 10 28 | -------------------------------------------------------------------------------- /client-side-lb/client-deploy.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: client-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: client 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: client 14 | spec: 15 | containers: 16 | - image: "jun06t/client-side-lb:client" 17 | imagePullPolicy: Always 18 | name: client 19 | env: 20 | - name: ENDPOINT 21 | value: "headless-svc:8080" 22 | - name: GRPC_VERBOSITY 23 | value: "DEBUG" 24 | - name: GRPC_GO_LOG_SEVERITY_LEVEL 25 | value: "info" 26 | - name: GRPC_GO_LOG_VERBOSITY_LEVEL 27 | value: "2" 28 | - name: GRPC_TRACE 29 | value: "all" 30 | # - name: GODEBUG 31 | # value: "http2debug=2" 32 | 33 | -------------------------------------------------------------------------------- /client-side-lb/server-deploy.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: server-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: server 9 | replicas: 3 10 | template: 11 | metadata: 12 | labels: 13 | app: server 14 | spec: 15 | containers: 16 | - image: "jun06t/client-side-lb:server" 17 | imagePullPolicy: Always 18 | name: server 19 | ports: 20 | - containerPort: 8080 21 | env: 22 | - name: MAX_CONNECTION_AGE 23 | value: "30" 24 | - name: GRPC_VERBOSITY 25 | value: "DEBUG" 26 | - name: GRPC_GO_LOG_SEVERITY_LEVEL 27 | value: "info" 28 | - name: GRPC_GO_LOG_VERBOSITY_LEVEL 29 | value: "2" 30 | - name: GRPC_TRACE 31 | value: "all" 32 | # - name: GODEBUG 33 | # value: "http2debug=2" 34 | -------------------------------------------------------------------------------- /probe/app/health.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "google.golang.org/grpc/codes" 7 | health "google.golang.org/grpc/health/grpc_health_v1" 8 | "google.golang.org/grpc/status" 9 | 10 | pb "github.com/jun06t/grpc-sample/unary/proto" 11 | ) 12 | 13 | type helloHandler struct{} 14 | 15 | func (h *helloHandler) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { 16 | return &pb.HelloReply{Message: "Hello " + in.Name}, nil 17 | } 18 | 19 | type healthHandler struct { 20 | } 21 | 22 | func (h *healthHandler) Check(context.Context, *health.HealthCheckRequest) (*health.HealthCheckResponse, error) { 23 | return &health.HealthCheckResponse{ 24 | Status: health.HealthCheckResponse_SERVING, 25 | }, nil 26 | } 27 | 28 | func (h *healthHandler) Watch(*health.HealthCheckRequest, health.Health_WatchServer) error { 29 | return status.Error(codes.Unimplemented, "watch is not implemented.") 30 | } 31 | -------------------------------------------------------------------------------- /envoy-service-mesh/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: configmap destroy apply apply-deployments apply-services 2 | 3 | configmap: 4 | kubectl create configmap envoy-config --from-file=envoy-config 5 | 6 | apply: apply-deployments apply-services 7 | 8 | apply-deployments: 9 | kubectl apply -f deployment-alive.yml 10 | kubectl apply -f deployment-user.yml 11 | kubectl apply -f deployment-gateway.yml 12 | 13 | apply-services: 14 | kubectl apply -f service-alive.yml 15 | kubectl apply -f service-alive-admin.yml 16 | kubectl apply -f service-user.yml 17 | kubectl apply -f service-user-admin.yml 18 | kubectl apply -f service-gateway.yml 19 | 20 | destroy: 21 | kubectl delete deployment gateway-deployment 22 | kubectl delete deployment alive-service-deployment 23 | kubectl delete deployment user-service-deployment 24 | kubectl delete service gateway-svc 25 | kubectl delete service user-svc 26 | kubectl delete service user-admin-svc 27 | kubectl delete service alive-admin-svc 28 | kubectl delete service alive-svc 29 | kubectl delete configmap envoy-config 30 | 31 | -------------------------------------------------------------------------------- /envoy-service-mesh/deployment-gateway.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: gateway-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: gateway 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: gateway 14 | spec: 15 | volumes: 16 | - name: envoy 17 | configMap: 18 | name: envoy-config 19 | containers: 20 | - name: gateway 21 | image: "jun06t/grpc-gateway" 22 | imagePullPolicy: IfNotPresent 23 | ports: 24 | - containerPort: 3000 25 | - name: envoy 26 | image: envoyproxy/envoy:latest 27 | imagePullPolicy: IfNotPresent 28 | volumeMounts: 29 | - name: envoy 30 | mountPath: /etc/envoy 31 | command: 32 | - "/usr/local/bin/envoy" 33 | args: 34 | - "--config-path /etc/envoy/sidecar-gateway.yaml" 35 | ports: 36 | - containerPort: 10000 37 | name: envoy-sidecar 38 | - containerPort: 10001 39 | name: envoy-admin 40 | -------------------------------------------------------------------------------- /envoy-service-mesh/deployment-user.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: user-service-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: user-service 9 | replicas: 2 10 | template: 11 | metadata: 12 | labels: 13 | app: user-service 14 | spec: 15 | volumes: 16 | - name: envoy 17 | configMap: 18 | name: envoy-config 19 | containers: 20 | - name: user 21 | image: "jun06t/grpc-backend" 22 | imagePullPolicy: IfNotPresent 23 | ports: 24 | - containerPort: 8080 25 | - name: envoy 26 | image: envoyproxy/envoy:latest 27 | imagePullPolicy: IfNotPresent 28 | volumeMounts: 29 | - name: envoy 30 | mountPath: /etc/envoy 31 | command: 32 | - "/usr/local/bin/envoy" 33 | args: 34 | - "--config-path /etc/envoy/sidecar-service.yaml" 35 | ports: 36 | - containerPort: 10000 37 | name: envoy-sidecar 38 | - containerPort: 10001 39 | name: envoy-admin 40 | -------------------------------------------------------------------------------- /envoy-service-mesh/deployment-alive.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: alive-service-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: alive-service 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: alive-service 14 | spec: 15 | volumes: 16 | - name: envoy 17 | configMap: 18 | name: envoy-config 19 | containers: 20 | - name: alive 21 | image: "jun06t/grpc-backend" 22 | imagePullPolicy: IfNotPresent 23 | ports: 24 | - containerPort: 8080 25 | - name: envoy 26 | image: envoyproxy/envoy:latest 27 | imagePullPolicy: IfNotPresent 28 | volumeMounts: 29 | - name: envoy 30 | mountPath: /etc/envoy 31 | command: 32 | - "/usr/local/bin/envoy" 33 | args: 34 | - "--config-path /etc/envoy/sidecar-service.yaml" 35 | ports: 36 | - containerPort: 10000 37 | name: envoy-sidecar 38 | - containerPort: 10001 39 | name: envoy-admin 40 | -------------------------------------------------------------------------------- /envoy-service-mesh/envoy-config/sidecar-service.yaml: -------------------------------------------------------------------------------- 1 | static_resources: 2 | listeners: 3 | - address: 4 | socket_address: 5 | address: 0.0.0.0 6 | port_value: 10000 7 | filter_chains: 8 | - filters: 9 | - name: envoy.http_connection_manager 10 | config: 11 | codec_type: auto 12 | stat_prefix: ingress_http 13 | route_config: 14 | name: local_route 15 | virtual_hosts: 16 | - name: service 17 | domains: 18 | - "*" 19 | routes: 20 | - match: 21 | prefix: "/" 22 | route: 23 | cluster: local_service 24 | access_log: 25 | - name: envoy.file_access_log 26 | config: 27 | path: "/dev/stdout" 28 | http_filters: 29 | - name: envoy.router 30 | config: {} 31 | clusters: 32 | - name: local_service 33 | http2_protocol_options: {} 34 | connect_timeout: 0.25s 35 | type: static 36 | lb_policy: round_robin 37 | health_checks: 38 | - timeout: 5s 39 | interval: 10s 40 | unhealthy_threshold: 2 41 | healthy_threshold: 2 42 | tcp_health_check: {} 43 | hosts: 44 | - socket_address: 45 | address: 127.0.0.1 46 | port_value: 8080 47 | admin: 48 | access_log_path: /dev/null 49 | address: 50 | socket_address: 51 | address: 0.0.0.0 52 | port_value: 10001 53 | -------------------------------------------------------------------------------- /nginx-ingress/README.md: -------------------------------------------------------------------------------- 1 | # How to use 2 | 3 | ## Before start 4 | ### Set virtual host 5 | Get minikube ip 6 | ``` 7 | $ minikube ip 8 | xxx.xxx.xxx.xxx 9 | ``` 10 | Add following line to /ets/hosts 11 | ``` 12 | xxx.xxx.xxx.xxx hello-world.info 13 | ``` 14 | 15 | ## Case 1: with minikube addons 16 | ### Run nginx-ingress-controller. 17 | ``` 18 | $ minikube addons enable ingress 19 | ``` 20 | 21 | ### Apply 22 | ``` 23 | $ make apply 24 | ``` 25 | 26 | ### Confirm 27 | Now you can access via virtual host. 28 | ``` 29 | $ curl hello-world.info 30 |