Skip to content

Commit

Permalink
kubernetes: Updated connectivity check
Browse files Browse the repository at this point in the history
Improved connectivity check with the ability to test various connectivity and
policy variations.

Signed-off-by: Thomas Graf <thomas@cilium.io>
  • Loading branch information
tgraf committed Feb 11, 2020
1 parent 7fc73b8 commit 54d9254
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 101 deletions.
24 changes: 3 additions & 21 deletions examples/kubernetes/connectivity-check/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
# Connectivity Checker App
# Connectivity Check

Deploys a simple echo REST API with multiple replicas. Probe pods with multiple
replicas checks connectivity to echo pods with a ClusterIP service. Readiness
and liveness probe of probes will fail if connectivity to echo pods are
unhealthy.

```
$ kubectl create -f connectivity-check.yaml
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
echo-7d9f9564df-2hkhp 1/1 Running 0 37s
echo-7d9f9564df-jr87s 1/1 Running 0 37s
echo-7d9f9564df-lk6dl 1/1 Running 0 37s
echo-7d9f9564df-q5dpb 1/1 Running 0 37s
echo-7d9f9564df-zwhtw 1/1 Running 0 37s
probe-8689f6579-899hc 1/1 Running 0 37s
probe-8689f6579-9wzz7 1/1 Running 0 37s
probe-8689f6579-k8ggp 1/1 Running 0 37s
probe-8689f6579-sqdfb 1/1 Running 0 37s
probe-8689f6579-thv7j 1/1 Running 0 37s
```
Set of deployments that will perform a series of connectivity checks via
liveness and readiness checks. An unhealthy/unready pod indicates a problem.
80 changes: 0 additions & 80 deletions examples/kubernetes/connectivity-check/connectivity-check.yaml

This file was deleted.

32 changes: 32 additions & 0 deletions examples/kubernetes/connectivity-check/echo-a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Service
metadata:
name: echo-a
spec:
type: ClusterIP
ports:
- port: 80
selector:
name: echo-a
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-a
spec:
selector:
matchLabels:
name: echo-a
replicas: 1
template:
metadata:
labels:
name: echo-a
spec:
containers:
- name: echo-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
readinessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "localhost"]
32 changes: 32 additions & 0 deletions examples/kubernetes/connectivity-check/echo-b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Service
metadata:
name: echo-b
spec:
type: ClusterIP
ports:
- port: 80
selector:
name: echo-b
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-b
spec:
selector:
matchLabels:
name: echo-b
replicas: 1
template:
metadata:
labels:
name: echo-b
spec:
containers:
- name: echo-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
readinessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "localhost"]
49 changes: 49 additions & 0 deletions examples/kubernetes/connectivity-check/pod-to-a-allowed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-to-a-allowed-cnp
spec:
selector:
matchLabels:
name: pod-to-a-allowed-cnp
replicas: 1
template:
metadata:
labels:
name: pod-to-a-allowed-cnp
spec:
containers:
- name: pod-to-a-allowed-cnp-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "echo-a"]
readinessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "echo-a"]
---
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "pod-to-a-allowed-cnp"
spec:
endpointSelector:
matchLabels:
name: pod-to-a-allowed-cnp
egress:
- toEndpoints:
- matchLabels:
name: echo-a
toPorts:
- ports:
- port: "80"
protocol: TCP
- toEndpoints:
- matchLabels:
k8s:io.kubernetes.pod.namespace: kube-system
k8s:k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
42 changes: 42 additions & 0 deletions examples/kubernetes/connectivity-check/pod-to-a-denied.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-to-a-l3-denied-cnp
spec:
selector:
matchLabels:
name: pod-to-a-l3-denied-cnp
replicas: 1
template:
metadata:
labels:
name: pod-to-a-l3-denied-cnp
spec:
containers:
- name: pod-to-a-l3-denied-cnp-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: ["bash", "-c", "! curl -sS --connect-timeout 5 -o /dev/null echo-a"]
readinessProbe:
exec:
command: ["bash", "-c", "! curl -sS --connect-timeout 5 -o /dev/null echo-a"]
---
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "pod-to-a-l3-denied-cnp"
spec:
endpointSelector:
matchLabels:
name: pod-to-a-l3-denied-cnp
egress:
- toEndpoints:
- matchLabels:
k8s:io.kubernetes.pod.namespace: kube-system
k8s:k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
21 changes: 21 additions & 0 deletions examples/kubernetes/connectivity-check/pod-to-a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-to-a
spec:
selector:
matchLabels:
name: pod-to-a
replicas: 1
template:
metadata:
labels:
name: pod-to-a
spec:
containers:
- name: pod-to-a-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "echo-a"]
31 changes: 31 additions & 0 deletions examples/kubernetes/connectivity-check/pod-to-b-intra-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-to-b-intra-node
spec:
selector:
matchLabels:
name: pod-to-b-intra-node
replicas: 1
template:
metadata:
labels:
name: pod-to-b-intra-node
spec:
containers:
- name: pod-to-b-intra-node-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "echo-b"]
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: name
operator: In
values:
- echo-b
topologyKey: "kubernetes.io/hostname"
31 changes: 31 additions & 0 deletions examples/kubernetes/connectivity-check/pod-to-b-multi-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-to-b-multi-node
spec:
selector:
matchLabels:
name: pod-to-b-multi-node
replicas: 1
template:
metadata:
labels:
name: pod-to-b-multi-node
spec:
containers:
- name: pod-to-b-multi-node-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: ["curl", "-sS", "-o", "/dev/null", "echo-b"]
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: name
operator: In
values:
- echo-b
topologyKey: "kubernetes.io/hostname"
24 changes: 24 additions & 0 deletions examples/kubernetes/connectivity-check/pod-to-external-1111.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pod-to-a-external-1111
spec:
selector:
matchLabels:
name: pod-to-a-external-1111
replicas: 1
template:
metadata:
labels:
name: pod-to-a-external-1111
spec:
containers:
- name: pod-to-a-external-1111-container
image: docker.io/cilium/json-mock:1.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command: ["bash", "-c", "curl -sS --connect-timeout 5 -o /dev/null 1.1.1.1"]
readinessProbe:
exec:
command: ["bash", "-c", "curl -sS --connect-timeout 5 -o /dev/null 1.1.1.1"]

0 comments on commit 54d9254

Please sign in to comment.