Skip to content

Commit 192f616

Browse files
committed
Add injector example and documentation
1 parent f7b2f0c commit 192f616

5 files changed

Lines changed: 181 additions & 0 deletions

File tree

docs/injection/injection.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Masher injection
2+
3+
Mesher can be used with any application language on any infrastructure. On Kubernetes, we inject Mesher into Pods, and applications can take advantage of all its features. Below we introduce the use of Mesher injector by example.
4+
5+
## Before
6+
1. Install Servcicecomb [service-center](http://servicecomb.apache.org/docs/service-center/install/#deployment-with-kubernetes)
7+
8+
9+
2. Download the example of quick_start
10+
```bash
11+
$ git clone https://github.com/apache/servicecomb-mesher.git
12+
$ cd ./servicecomb-mesher/examples/quick_start
13+
```
14+
15+
3. Build docker images
16+
```bash
17+
$ cd ./mesher_injection
18+
$ bash build_images.sh
19+
```
20+
21+
## Automatic Mesher injection
22+
Meshers can be automatically added to applicable Kubernetes pods using a mutating webhook admission controller provided by Mesher Injector.
23+
24+
1. Create namespace "svccomb-system"
25+
```bash
26+
cp ../../../deployments/kubernetes/injector/*.yaml .
27+
$ kubectl apply -f svccomb-system.yaml
28+
namespace/svccomb-system created
29+
```
30+
2. Generate Injector's certificatesigningrequest and secret
31+
```bash
32+
$ wget https://raw.githubusercontent.com/morvencao/kube-mutating-webhook-tutorial/master/deployment/webhook-create-signed-cert.sh
33+
34+
$ bash webhook-create-signed-cert.sh --service svccomb-mesher-injector --namespace svccomb-system --secret svccomb-mesher-injector-service-account
35+
```
36+
3. Query caBundle and fill it into "mesher-injector.yaml"
37+
```bash
38+
$ CA_BUNDLE=$(kubectl config view --raw --minify --flatten -o jsonpath='{.clusters[].cluster.certificate-authority-data}')
39+
40+
$ sed -i "s|\${CA_BUNDLE}|${CA_BUNDLE}|g" mesher-injector.yaml
41+
```
42+
4. Deploy mesher injecter
43+
```bash
44+
$ kubectl apply -f mesher-injector.yaml
45+
mutatingwebhookconfiguration.admissionregistration.k8s.io/svccomb-mesher-injector configured
46+
service/svccomb-mesher-injector created
47+
deployment.extensions/svccomb-mesher-injector created
48+
```
49+
5. Deploy examples to Kubernetes
50+
```bash
51+
$ kubectl apply -f svccomb-test.yaml
52+
namespace/svccomb-test created
53+
54+
$ kubectl -n svccomb-test apply -f calculator.yaml
55+
service/calculator created
56+
deployment.extensions/calculator-python created
57+
58+
$ kubectl -n svccomb-test apply -f webapp.yaml
59+
service/webapp created
60+
deployment.extensions/webapp-node created
61+
```
62+
6. Validated results
63+
```bash
64+
$ kubectl get svc
65+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
66+
calculator ClusterIP 10.104.2.143 <none> 5000/TCP 3m43s
67+
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 42d
68+
webapp NodePort 10.104.134.148 <none> 5001:30062/TCP 3m35s
69+
```
70+
Open the page "http://127.0.0.1:30062" in your browser, enter your height and weight in the input boxes, and click the submit button, you can see the BMI results about you.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:2
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY httpserver_calculator/ ./
6+
7+
CMD [ "python", "httpserver_calculator.py" ]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:10.16.2
2+
3+
WORKDIR /home
4+
5+
COPY httpserver_webapp/ ./
6+
7+
RUN npm install
8+
9+
CMD [ "node", "httpserver_webapp.js" ]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
echo "copy resource"
3+
cp -r ../httpserver_* .
4+
5+
echo "build calculator image"
6+
cp -f Dockerfile_calculator Dockerfile
7+
docker build -t servicecomb/calculator-python:latest .
8+
9+
echo "build webapp image"
10+
cp -f Dockerfile_webapp Dockerfile
11+
docker build -t servicecomb/webapp-node:latest .
12+
13+
echo "clean"
14+
rm -rf httpserver_* Dockerfile
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# svccomb-test namespace
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: svccomb-test
6+
labels:
7+
svccomb-injection: enabled
8+
---
9+
# calculator service
10+
apiVersion: v1
11+
kind: Service
12+
metadata:
13+
name: calculator
14+
namespace: svccomb-test
15+
labels:
16+
app: calculator
17+
spec:
18+
ports:
19+
- port: 5000
20+
name: http
21+
targetPort: 4540
22+
selector:
23+
app: calculator
24+
---
25+
# calculator deployment
26+
apiVersion: extensions/v1beta1
27+
kind: Deployment
28+
metadata:
29+
name: calculator-python
30+
namespace: svccomb-test
31+
spec:
32+
replicas: 1
33+
template:
34+
metadata:
35+
labels:
36+
app: calculator
37+
spec:
38+
containers:
39+
- name: calculator
40+
image: servicecomb/calculator-python:latest
41+
imagePullPolicy: IfNotPresent #Always
42+
ports:
43+
- containerPort: 4540
44+
---
45+
# webapp service
46+
apiVersion: v1
47+
kind: Service
48+
metadata:
49+
name: webapp
50+
namespace: svccomb-test
51+
labels:
52+
app: webapp
53+
spec:
54+
type: NodePort
55+
ports:
56+
- port: 5001
57+
name: http
58+
targetPort: 4597
59+
nodePort: 30062
60+
selector:
61+
app: webapp
62+
---
63+
# webapp deployment
64+
apiVersion: extensions/v1beta1
65+
kind: Deployment
66+
metadata:
67+
name: webapp-node
68+
namespace: svccomb-test
69+
spec:
70+
replicas: 1
71+
template:
72+
metadata:
73+
labels:
74+
app: webapp
75+
spec:
76+
containers:
77+
- name: webapp
78+
image: servicecomb/webapp-node:latest
79+
imagePullPolicy: IfNotPresent #Always
80+
ports:
81+
- containerPort: 4597

0 commit comments

Comments
 (0)