Skip to content

Commit f5871df

Browse files
committed
update module4
1 parent 7140d43 commit f5871df

14 files changed

+184
-0
lines changed

module14/allow-icmp-incluster.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: projectcalico.org/v3
2+
kind: GlobalNetworkPolicy
3+
metadata:
4+
name: allow-ping-in-cluster
5+
spec:
6+
selector: all()
7+
types:
8+
- Ingress
9+
ingress:
10+
- action: Allow
11+
protocol: ICMP
12+
source:
13+
selector: all()
14+
icmp:
15+
type: 8 # Ping request
16+
- action: Allow
17+
protocol: ICMPv6
18+
source:
19+
selector: all()
20+
icmp:
21+
type: 128 # Ping request

module14/networkpolicy.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
namespace: default
5+
name: toolbox
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
app: toolbox
11+
template:
12+
metadata:
13+
labels:
14+
app: toolbox
15+
access: "true"
16+
spec:
17+
containers:
18+
- name: toolbox
19+
image: centos
20+
command:
21+
- tail
22+
- -f
23+
- /dev/null
24+
---
25+
kind: NetworkPolicy
26+
apiVersion: networking.k8s.io/v1
27+
metadata:
28+
name: default-deny
29+
namespace: ns-calico-01
30+
spec:
31+
podSelector: {}
32+
---

module3/setup-network.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
### create network ns
2+
```
3+
mkdir -p /var/run/netns
4+
find -L /var/run/netns -type l -delete
5+
```
6+
### start nginx docker with non network mode
7+
```
8+
docker run --network=none -d nginx
9+
```
10+
### check corresponding pid
11+
```
12+
docker ps|grep nginx
13+
docker inspect <containerid>|grep -i pid
14+
15+
"Pid": 876884,
16+
"PidMode": "",
17+
"PidsLimit": null,
18+
```
19+
### check network config for the container
20+
```
21+
nsenter -t 876884 -n ip a
22+
```
23+
### link network namespace
24+
```
25+
export pid=876884
26+
ln -s /proc/$pid/ns/net /var/run/netns/$pid
27+
ip netns list
28+
```
29+
### check docker bridge on the host
30+
```
31+
brctl show
32+
ip a
33+
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
34+
link/ether 02:42:35:40:d3:8b brd ff:ff:ff:ff:ff:ff
35+
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
36+
valid_lft forever preferred_lft forever
37+
inet6 fe80::42:35ff:fe40:d38b/64 scope link
38+
valid_lft forever preferred_lft forever
39+
```
40+
### create veth pair
41+
```
42+
ip link add A type veth peer name B
43+
```
44+
### config A
45+
```
46+
brctl addif docker0 A
47+
ip link set A up
48+
```
49+
### config B
50+
```
51+
SETIP=172.17.0.10
52+
SETMASK=16
53+
GATEWAY=172.17.0.1
54+
55+
ip link set B netns $pid
56+
ip netns exec $pid ip link set dev B name eth0
57+
ip netns exec $pid ip link set eth0 up
58+
ip netns exec $pid ip addr add $SETIP/$SETMASK dev eth0
59+
ip netns exec $pid ip route add default via $GATEWAY
60+
```
61+
### check connectivity
62+
```
63+
curl 172.17.0.10
64+
```

module4/1.simple-pod.MD

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
## simple pod demo
3+
### run nginx as webserver
4+
```
5+
$ kubectl run --image=nginx nginx
6+
```
7+
### show running pod
8+
```
9+
$ kubectl get po --show-labels -owide -w
10+
```
11+
### expose svc
12+
```
13+
$ kubectl expose deploy nginx --selector run=nginx --port=80 --type=NodePort
14+
```
15+
### check svc detail
16+
```
17+
$ kubectl get svc
18+
```
19+
### access service
20+
```
21+
$ curl 192.168.34.2:<nodeport>
22+
```

module4/2.run-envoy-with-configmap.MD

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## run envoy
2+
```
3+
$ kubectl create configmap envoy-config --from-file=envoy.yaml
4+
$ kubectl create -f envoy-deploy.yaml
5+
$ kubectl expose deploy envoy --selector run=envoy --port=10000 --type=NodePort
6+
```
7+
## access service
8+
```
9+
$ curl 192.168.34.2:<nodeport>
10+
```
11+
## scale up/down/failover
12+
```
13+
$ kubectl scale deploy <deployment-name> --replicas=<n>
14+
```

module4/3.understand-configmap.MD

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# configmap
2+
```
3+
cat game.properties
4+
5+
#configmap from file
6+
kubectl create configmap game-config --from-file=game.properties
7+
kubectl create configmap game-env-config --from-env-file=game.properties
8+
kubectl get configmap -oyaml game-config
9+
```
10+
## configmap from literal
11+
```
12+
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
13+
#downward api pod
14+
kubectl create -f downward-api-pod.yaml
15+
kubectl get po downward-api-pod
16+
kubectl logs -f downward-api-pod
17+
```

module4/4.configmap-volume.MD

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# volume
2+
```
3+
kubectl create -f configmap-volume-pod.yaml
4+
kubectl get po
5+
kubectl logs -f configmap-volume-pod
6+
```

module4/5.readiness-probe.MD

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# readiness probe
2+
```
3+
kubectl create -f centos-readiness.yaml
4+
```

module4/6.get-obj-columns.MD

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## get object by columns
2+
```
3+
kubectl get svc -o=custom-columns=NAME:.metadata.name,CREATED:'.metadata.annotations'
4+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)