Skip to content

Commit 6e9c0c0

Browse files
committed
refactor
1 parent 1fcf8da commit 6e9c0c0

34 files changed

+1836
-119
lines changed

Diff for: Jenkinsfile

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ node {
2323
stage "Deploy"
2424

2525
sh "sed 's#127.0.0.1:30400/hello-kenzan:latest#'$BUILDIMG'#' applications/hello-kenzan/k8s/deployment.yaml | kubectl apply -f -"
26+
sh "kubectl rollout status deployment/hello-kenzan"
2627
}

Diff for: README.md

+6-111
Original file line numberDiff line numberDiff line change
@@ -13,124 +13,19 @@ Begin the tutorial `npm start`
1313

1414
## Manual tutorial version
1515

16-
## Part 1
16+
## Part 4
1717

1818

19-
### Part 1
19+
### Part 4
2020

2121
### Step1
2222

23-
Start up the cluster with minikibe
23+
Bootstrap etcd operator on the cluster
2424

25-
`minikube start --memory 6000 --cpus 2 --kubernetes-version v1.6.0`
25+
`scripts/etcd.sh`
2626

2727
### Step2
2828

29-
Enable addons
29+
Setup etcd directory for kubescale
3030

31-
`minikube addons enable heapster; minikube addons enable ingress`
32-
33-
### Step3
34-
35-
Wait 20 seconds and view minikube dashboard
36-
37-
`sleep 20; minikube service kubernetes-dashboard --namespace kube-system`
38-
39-
### Step4
40-
41-
Deploy the public nginx image from DockerHub
42-
43-
`kubectl run nginx --image nginx --port 80`
44-
45-
### Step5
46-
47-
Create a service for deployment
48-
49-
`kubectl expose deployment nginx --type NodePort --port 80`
50-
51-
### Step6
52-
53-
Launch browser to test service
54-
55-
`minikube service nginx`
56-
57-
### Step7
58-
59-
Install registry
60-
61-
`kubectl apply -f manifests/registry.yml`
62-
63-
### Step8
64-
65-
Wait for registry to deploy
66-
67-
`kubectl rollout status deployments/registry`
68-
69-
### Step9
70-
71-
View registry UI
72-
73-
`minikube service registry-ui`
74-
75-
### Step10
76-
77-
Edit the contents of applications/hello-kenzan/index.html
78-
79-
`nano applications/hello-kenzan/index.html`
80-
81-
### Step11
82-
83-
We will now build the image with a special name that is pointing at our cluster registry.
84-
85-
`docker build -t 127.0.0.1:30400/hello-kenzan:latest -f applications/hello-kenzan/Dockerfile applications/hello-kenzan`
86-
87-
### Step12
88-
89-
Before we can push our image we need to set up a temporary proxy. This is a container that listens on 127.0.0.1:30400 and forwads to our cluster. By default the docker client can only push to non https via localhost.
90-
91-
`docker run -d -e "REGIP=`minikube ip`" --name socat-registry -p 30400:5000 chadmoon/socat:latest bash -c "socat TCP4-LISTEN:5000,fork,reuseaddr TCP4:`minikube ip`:30400"`
92-
93-
### Step13
94-
95-
We can now push our image.
96-
97-
`docker push 127.0.0.1:30400/hello-kenzan:latest`
98-
99-
### Step14
100-
101-
Stop the registry proxy
102-
103-
`docker stop socat-registry; docker rm socat-registry`
104-
105-
### Step15
106-
107-
Now that our image is on the cluster we can deploy the manifests
108-
109-
`kubectl apply -f applications/hello-kenzan/k8s/deployment.yaml`
110-
111-
### Step16
112-
113-
View the app
114-
115-
`minikube service hello-kenzan`## Part 2
116-
117-
118-
### Part 2
119-
120-
### Step1
121-
122-
Install Jenkins
123-
124-
`kubectl apply -f manifests/jenkins.yml; kubectl rollout status deployment/jenkins`
125-
126-
### Step2
127-
128-
Get Jenkins admin password
129-
130-
`kubectl exec -it `kubectl get pods --selector=app=jenkins --output=jsonpath={.items..metadata.name}` cat /root/.jenkins/secrets/initialAdminPassword`
131-
132-
### Step3
133-
134-
Configure Jenkins, default settings. Create a new job with type pipeline. Choose "Jenkinsfile from SCM" with target repo as https://github.com/kenzanlabs/kubernetes-ci-cd.git. Run the job.
135-
136-
`minikube service jenkins`
31+
`scripts/kubescale.sh`

Diff for: applications/kubescale/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:6
2+
3+
RUN mkdir /app
4+
5+
COPY . /app
6+
7+
WORKDIR /app
8+
9+
RUN apt-get update
10+
11+
RUN apt-get install -y apache2
12+
13+
RUN npm install -g loadtest
14+
15+
RUN npm install -g nodemon
16+
17+
RUN npm install
18+
19+
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
20+
21+
RUN chmod +x ./kubectl; mv ./kubectl /usr/local/bin/kubectl
22+
23+
CMD ["nodemon", "index.js"]

Diff for: applications/kubescale/index.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
var express = require('express')
2+
var app = express()
3+
4+
var http = require('http').Server(app);
5+
var io = require('socket.io')(http);
6+
var path = require("path");
7+
var Etcd = require('node-etcd')
8+
app.use(express.static('public'))
9+
var exec = require('child_process').exec;
10+
11+
var bodyParser = require("body-parser");
12+
13+
app.use(bodyParser.urlencoded({ extended: false }));
14+
app.use(bodyParser.json());
15+
16+
//etcd = new Etcd("http://localhost:2379")
17+
///tmp/test-etcd/etcdctl --endpoints "http://example-etcd-cluster-client-service:2379" mkdir pod-list
18+
etcd = new Etcd("http://example-etcd-cluster-client-service:2379")
19+
20+
//etcd.mkdir("pods");
21+
22+
watcher = etcd.watcher("pod-list", null, {recursive: true})
23+
24+
watcher.on("change", showVal);
25+
26+
function showVal(val) {
27+
pods = etcd.getSync("pod-list",{ recursive: true })
28+
io.emit('pods', { pods: pods.body.node.nodes });
29+
30+
}
31+
32+
app.post('/scale', function (req, res) {
33+
exec('kubectl scale --replicas=' + req.body.count + ' deployment/set', function(error, stdout, stderr) {
34+
res.send("scaled to " + req.body.count);
35+
});
36+
})
37+
38+
app.post('/loadtest/concurrent', function (req, res) {
39+
//svc = "http://localhost:8001/api/v1/proxy/namespaces/default/services/set:80"
40+
svc = "http://set:80/"
41+
// exec('loadtest -c ' + req.body.count + ' -n ' + req.body.count + ' http://set', function(error, stdout, stderr) {
42+
exec('ab -c ' + req.body.count + ' -n ' + req.body.count + ' ' + svc, function(error, stdout, stderr) {
43+
console.log(stdout);
44+
res.send(stdout);
45+
});
46+
})
47+
48+
app.post('/loadtest/consecutive', function (req, res) {
49+
svc = "http://set:80/"
50+
// exec('loadtest -c ' + req.body.count + ' -n ' + req.body.count + ' http://set', function(error, stdout, stderr) {
51+
exec('ab -c 1 -n ' + req.body.count + ' ' + svc, function(error, stdout, stderr) {
52+
console.log(stdout);
53+
res.send(stdout);
54+
});
55+
})
56+
57+
58+
59+
app.get('/up/:podId', function (req, res) {
60+
etcd.set("pod-list/" + req.params.podId, req.params.podId);
61+
res.send('done');
62+
})
63+
64+
app.get('/down/:podId', function (req, res) {
65+
etcd.del("pod-list/" + req.params.podId, req.params.podId);
66+
res.send('done');
67+
})
68+
69+
app.get('/hit/:podId', function (req, res) {
70+
71+
var d = new Date();
72+
var n = d.getTime();
73+
74+
io.emit('hit', { podId: req.params.podId, time: n });
75+
console.log('hit!');
76+
res.send('done')
77+
})
78+
79+
io.on('connection', function(socket){
80+
81+
pods = etcd.getSync("pod-list",{ recursive: true })
82+
io.emit('pods', { pods: pods.body.node.nodes });
83+
});
84+
85+
app.get('/',function(req,res){
86+
87+
res.sendFile(path.join(__dirname+'/public/index.html'));
88+
89+
});
90+
91+
92+
http.listen(3000, function () {
93+
console.log('Example app listening on port 3000!')
94+
})
95+

Diff for: applications/kubescale/k8s/dashboard-ingress.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: extensions/v1beta1
3+
kind: Ingress
4+
metadata:
5+
name: dashboard-ingress
6+
namespace: kube-system
7+
spec:
8+
rules:
9+
- host: dashboard.127.0.0.1.xip.io
10+
http:
11+
paths:
12+
- path: /
13+
backend:
14+
serviceName: kubernetes-dashboard
15+
servicePort: 80

Diff for: applications/kubescale/k8s/ing.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Ingress
3+
metadata:
4+
name: ingress-services
5+
namespace: kube-system
6+
annotations:
7+
ingress.kubernetes.io/rewrite-target: /
8+
spec:
9+
backend:
10+
serviceName: default-http-backend
11+
servicePort: 80
12+
rules:
13+
- host: dashboard.127.0.0.1.xip.io
14+
http:
15+
paths:
16+
- path: /
17+
backend:
18+
serviceName: kubernetes-dashboard
19+
servicePort: 80
20+
21+
- host: grafana.127.0.0.1.xip.io
22+
http:
23+
paths:
24+
- path: /
25+
backend:
26+
serviceName: monitoring-grafana
27+
servicePort: 80
28+
---
29+
apiVersion: extensions/v1beta1
30+
kind: Ingress
31+
metadata:
32+
name: ingress-services
33+
annotations:
34+
ingress.kubernetes.io/rewrite-target: /
35+
spec:
36+
backend:
37+
serviceName: default-http-backend
38+
servicePort: 80
39+
rules:
40+
- host: kubescale.127.0.0.1.xip.io
41+
http:
42+
paths:
43+
- path: /
44+
backend:
45+
serviceName: kubescale
46+
servicePort: 3000

0 commit comments

Comments
 (0)