├── README.md ├── client-side-lb ├── client-deploy.yml ├── headless-svc.yml └── server-deploy.yml ├── envoy-service-mesh ├── Makefile ├── README.md ├── deployment-alive.yml ├── deployment-gateway.yml ├── deployment-user.yml ├── envoy-config │ ├── sidecar-gateway.yaml │ └── sidecar-service.yaml ├── service-alive-admin.yml ├── service-alive.yml ├── service-gateway.yml ├── service-user-admin.yml └── service-user.yml ├── headless ├── deployment.yml └── service.yml ├── helm-rbac ├── clusterrolebinding.yaml └── sa.yaml ├── helm ├── mychart │ ├── .helmignore │ ├── Chart.yaml │ ├── templates │ │ └── configmap.yaml │ └── values.yaml └── override.yaml ├── neg ├── deploy.yaml ├── ingress.yaml └── svc.yaml ├── nginx-ingress ├── Makefile ├── README.md ├── deployment.yml ├── ingress.yml └── service.yml ├── probe ├── Dockerfile ├── Makefile ├── app │ ├── go.mod │ ├── go.sum │ ├── health.go │ └── main.go └── probe-deployment.yaml ├── resource ├── image │ ├── Dockerfile │ └── main.go └── resource.yaml ├── service-account ├── Makefile ├── clusterrolebinding.yaml ├── pod.yaml └── sa.yaml └── service ├── clusterip.yml ├── deploy.yaml └── nodeport.yml /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Sample 2 | -- 3 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/envoy-config/sidecar-gateway.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 | - address: 32 | socket_address: 33 | address: 127.0.0.1 34 | port_value: 8080 35 | filter_chains: 36 | - filters: 37 | - name: envoy.http_connection_manager 38 | config: 39 | codec_type: auto 40 | stat_prefix: egress_http 41 | route_config: 42 | name: local_route 43 | virtual_hosts: 44 | - name: alive 45 | domains: 46 | - "*" 47 | routes: 48 | - match: 49 | prefix: "/gateway.AliveService" 50 | route: 51 | cluster: alive 52 | - match: 53 | prefix: "/gateway.UserService" 54 | route: 55 | cluster: user 56 | access_log: 57 | - name: envoy.file_access_log 58 | config: 59 | path: "/dev/stdout" 60 | http_filters: 61 | - name: envoy.router 62 | config: {} 63 | clusters: 64 | - name: local_service 65 | connect_timeout: 0.25s 66 | type: static 67 | lb_policy: round_robin 68 | health_checks: 69 | - timeout: 5s 70 | interval: 10s 71 | unhealthy_threshold: 2 72 | healthy_threshold: 2 73 | tcp_health_check: {} 74 | hosts: 75 | - socket_address: 76 | address: 127.0.0.1 77 | port_value: 3000 78 | - name: alive 79 | http2_protocol_options: {} 80 | connect_timeout: 0.25s 81 | type: strict_dns 82 | lb_policy: round_robin 83 | health_checks: 84 | - timeout: 5s 85 | interval: 10s 86 | unhealthy_threshold: 2 87 | healthy_threshold: 2 88 | tcp_health_check: {} 89 | hosts: 90 | - socket_address: 91 | address: alive-svc 92 | port_value: 10000 93 | - name: user 94 | http2_protocol_options: {} 95 | connect_timeout: 0.25s 96 | type: strict_dns 97 | lb_policy: round_robin 98 | health_checks: 99 | - timeout: 5s 100 | interval: 10s 101 | unhealthy_threshold: 2 102 | healthy_threshold: 2 103 | tcp_health_check: {} 104 | hosts: 105 | - socket_address: 106 | address: user-svc 107 | port_value: 10000 108 | admin: 109 | access_log_path: /dev/null 110 | address: 111 | socket_address: 112 | address: 0.0.0.0 113 | port_value: 10001 114 | 115 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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-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 | -------------------------------------------------------------------------------- /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-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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-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 | -------------------------------------------------------------------------------- /helm-rbac/sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: tiller 5 | namespace: helm 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /helm/mychart/values.yaml: -------------------------------------------------------------------------------- 1 | favorite: 2 | drink: coffee 3 | food: pizza 4 | pizzaToppings: 5 | - mushrooms 6 | - cheese 7 | - peppers 8 | - onions 9 | -------------------------------------------------------------------------------- /helm/override.yaml: -------------------------------------------------------------------------------- 1 | favorite: 2 | drink: tea 3 | food: rice 4 | 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 |