Skip to content

Commit ba56aa5

Browse files
authored
Merge pull request #20 from denhamparry/master
fix: kubectl run creates pod not deployment
2 parents 2680594 + d7b7c4c commit ba56aa5

File tree

4 files changed

+161
-44
lines changed

4 files changed

+161
-44
lines changed

Makefile

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,25 +211,11 @@ test-local: ## test from the local machine
211211
.PHONY: test-deploy
212212
test-deploy: ## deploy test services
213213
@echo "+ $@"
214-
set -x; for DEPLOYMENT_TYPE in \
215-
frontend \
216-
microservice \
217-
database \
218-
; do \
219-
\
220-
DEPLOYMENT="test-$${DEPLOYMENT_TYPE}"; \
221-
kubectl run "$${DEPLOYMENT}" \
222-
--image=busybox \
223-
--labels=app=web,role="$${DEPLOYMENT_TYPE}" \
224-
--requests='cpu=10m,memory=32Mi' \
225-
--expose \
226-
--port 80 \
227-
-- sh -c "while true; do { printf 'HTTP/1.1 200 OK\r\n\n I am a $${DEPLOYMENT_TYPE}\n'; } | nc -l -p 80; done"; \
228-
\
229-
kubectl scale deployment "$${DEPLOYMENT}" --replicas=3; \
230-
done; \
231-
\
232-
kubectl apply -f resource/net-pol/web-deny-all.yaml -f resource/net-pol/test-services-allow.yaml;
214+
set -x;
215+
kubectl apply \
216+
-f resource/deployment/demo.yaml \
217+
-f resource/net-pol/web-deny-all.yaml \
218+
-f resource/net-pol/test-services-allow.yaml;
233219

234220

235221
.PHONY: rollcage

README.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ More information and background in [this presentation](https://www.binarysludge.
4343
Usage: netassert [options] [filename]
4444
4545
Options:
46-
46+
4747
--image Name of test image
4848
--no-pull Don't pull test container on target nodes
4949
--timeout Integer time to wait before giving up on tests (default 120)
50-
50+
5151
--ssh-user SSH user for kubelet host
5252
--ssh-options Optional options to pass to the 'gcloud compute ssh' command
5353
--known-hosts A known_hosts file (default: ${HOME}/.ssh/known_hosts)
54-
54+
5555
--debug More debug
5656
-h --help Display this message
5757
```
@@ -72,24 +72,15 @@ Options:
7272
- `docker`
7373

7474
### Deploy fake mini-microservices
75+
7576
```bash
76-
for DEPLOYMENT_TYPE in \
77-
frontend \
78-
microservice \
79-
database\
80-
; do
81-
DEPLOYMENT="test-${DEPLOYMENT_TYPE}"
82-
83-
kubectl run "${DEPLOYMENT}" \
84-
--image=busybox \
85-
--labels=app=web,role="${DEPLOYMENT_TYPE}" \
86-
--requests='cpu=10m,memory=32Mi' \
87-
--expose \
88-
--port 80 \
89-
-- sh -c "while true; do { printf 'HTTP/1.1 200 OK\r\n\n I am a ${DEPLOYMENT_TYPE}\n'; } | nc -l -p 80; done"
90-
91-
kubectl scale deployment "${DEPLOYMENT}" --replicas=3
92-
done
77+
$ kubectl apply -f resource/deployment/demo.yaml
78+
service/test-database created
79+
deployment.apps/test-database created
80+
service/test-frontend created
81+
deployment.apps/test-frontend created
82+
service/test-microservice created
83+
deployment.apps/test-microservice created
9384
```
9485

9586
### Run netassert (this should fail)

resource/deployment/demo.yaml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: test-database
5+
spec:
6+
selector:
7+
app: web
8+
role: test-database
9+
ports:
10+
- protocol: TCP
11+
port: 80
12+
targetPort: 80
13+
---
14+
apiVersion: apps/v1
15+
kind: Deployment
16+
metadata:
17+
labels:
18+
app: web
19+
role: test-database
20+
name: test-database
21+
spec:
22+
replicas: 3
23+
selector:
24+
matchLabels:
25+
app: web
26+
role: test-database
27+
template:
28+
metadata:
29+
labels:
30+
app: web
31+
role: test-database
32+
spec:
33+
containers:
34+
- args:
35+
- sh
36+
- -c
37+
- while true; do { printf 'HTTP/1.1 200 OK\r\n\n I am a test database\n'; } | nc -l -p 80; done
38+
image: busybox
39+
name: alpine
40+
resources:
41+
requests:
42+
cpu: 10m
43+
memory: 32Mi
44+
ports:
45+
- containerPort: 80
46+
protocol: TCP
47+
---
48+
apiVersion: v1
49+
kind: Service
50+
metadata:
51+
name: test-frontend
52+
spec:
53+
selector:
54+
app: web
55+
role: test-frontend
56+
ports:
57+
- protocol: TCP
58+
port: 80
59+
targetPort: 80
60+
---
61+
apiVersion: apps/v1
62+
kind: Deployment
63+
metadata:
64+
labels:
65+
app: web
66+
role: test-frontend
67+
name: test-frontend
68+
spec:
69+
replicas: 3
70+
selector:
71+
matchLabels:
72+
app: web
73+
role: test-frontend
74+
template:
75+
metadata:
76+
labels:
77+
app: web
78+
role: test-frontend
79+
spec:
80+
containers:
81+
- args:
82+
- sh
83+
- -c
84+
- while true; do { printf 'HTTP/1.1 200 OK\r\n\n I am a test frontend\n'; } | nc -l -p 80; done
85+
image: busybox
86+
name: alpine
87+
resources:
88+
requests:
89+
cpu: 10m
90+
memory: 32Mi
91+
ports:
92+
- containerPort: 80
93+
protocol: TCP
94+
---
95+
apiVersion: v1
96+
kind: Service
97+
metadata:
98+
name: test-microservice
99+
spec:
100+
selector:
101+
app: web
102+
role: test-microservice
103+
ports:
104+
- protocol: TCP
105+
port: 80
106+
targetPort: 80
107+
---
108+
apiVersion: apps/v1
109+
kind: Deployment
110+
metadata:
111+
labels:
112+
app: web
113+
role: test-microservice
114+
name: test-microservice
115+
spec:
116+
replicas: 3
117+
selector:
118+
matchLabels:
119+
app: web
120+
role: test-microservice
121+
template:
122+
metadata:
123+
labels:
124+
app: web
125+
role: test-microservice
126+
spec:
127+
containers:
128+
- args:
129+
- sh
130+
- -c
131+
- while true; do { printf 'HTTP/1.1 200 OK\r\n\n I am a test microservice\n'; } | nc -l -p 80; done
132+
image: busybox
133+
name: alpine
134+
resources:
135+
requests:
136+
cpu: 10m
137+
memory: 32Mi
138+
ports:
139+
- containerPort: 80
140+
protocol: TCP

resource/net-pol/test-services-allow.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
podSelector:
77
matchLabels:
88
app: web
9-
role: frontend
9+
role: test-frontend
1010
ingress:
1111
- from: []
1212
---
@@ -18,13 +18,13 @@ spec:
1818
podSelector:
1919
matchLabels:
2020
app: web
21-
role: microservice
21+
role: test-microservice
2222
ingress:
2323
- from:
2424
- podSelector:
2525
matchLabels:
2626
app: web
27-
role: frontend
27+
role: test-frontend
2828
---
2929
kind: NetworkPolicy
3030
apiVersion: networking.k8s.io/v1
@@ -34,10 +34,10 @@ spec:
3434
podSelector:
3535
matchLabels:
3636
app: web
37-
role: database
37+
role: test-database
3838
ingress:
3939
- from:
4040
- podSelector:
4141
matchLabels:
4242
app: web
43-
role: microservice
43+
role: test-microservice

0 commit comments

Comments
 (0)