diff --git a/additions/sctp-client/Dockerfile b/additions/sctp-client/Dockerfile new file mode 100644 index 0000000..82e06d3 --- /dev/null +++ b/additions/sctp-client/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.8-slim-buster + +WORKDIR /app +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt +RUN apt-get update +RUN apt-get -y install curl procps +COPY example.py . +COPY run.sh . diff --git a/additions/sctp-client/build.sh b/additions/sctp-client/build.sh new file mode 100755 index 0000000..f9849c6 --- /dev/null +++ b/additions/sctp-client/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build . -t mertyildiran/mizutest-sctp-client:latest && docker push mertyildiran/mizutest-sctp-client:latest diff --git a/additions/sctp-client/example.py b/additions/sctp-client/example.py new file mode 100644 index 0000000..0f2d1b3 --- /dev/null +++ b/additions/sctp-client/example.py @@ -0,0 +1,32 @@ +import socket +import sctp +import time + +print("Start SCTP client") + +sock = sctp.sctpsocket_tcp(socket.AF_INET) + +cnt = 0 +connected = False +while True: + if not connected: + try: + sock.connect(("mizutest-sctp-server", 50051)) + except: + print("couldn't connect") + time.sleep(3) + continue + + connected = True + + msg = 'hello world %s' % cnt + sock.sctp_send(msg=msg) + print("Sent %s" % msg) + cnt += 1 + + time.sleep(3) + +sock.shutdown(0) + + +sock.close() diff --git a/additions/sctp-client/requirements.txt b/additions/sctp-client/requirements.txt new file mode 100644 index 0000000..c9c33e2 --- /dev/null +++ b/additions/sctp-client/requirements.txt @@ -0,0 +1 @@ +pysctp==0.7.2 diff --git a/additions/sctp-client/run.sh b/additions/sctp-client/run.sh new file mode 100755 index 0000000..e93d9c3 --- /dev/null +++ b/additions/sctp-client/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 example.py diff --git a/additions/sctp-server/Dockerfile b/additions/sctp-server/Dockerfile new file mode 100644 index 0000000..82e06d3 --- /dev/null +++ b/additions/sctp-server/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.8-slim-buster + +WORKDIR /app +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt +RUN apt-get update +RUN apt-get -y install curl procps +COPY example.py . +COPY run.sh . diff --git a/additions/sctp-server/build.sh b/additions/sctp-server/build.sh new file mode 100755 index 0000000..e3a8793 --- /dev/null +++ b/additions/sctp-server/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build . -t mertyildiran/mizutest-sctp-server:latest && docker push mertyildiran/mizutest-sctp-server:latest diff --git a/additions/sctp-server/example.py b/additions/sctp-server/example.py new file mode 100644 index 0000000..0a7aee4 --- /dev/null +++ b/additions/sctp-server/example.py @@ -0,0 +1,35 @@ +import socket +import sctp + +print("Start SCTP server") + +host = '0.0.0.0' +port = 50051 + +sock = sctp.sctpsocket_tcp(socket.AF_INET) +sock.bind((host, port)) +sock.listen(1) + +while True: + # wait for a connection + print ('waiting for a connection') + connection, client_address = sock.accept() + + try: + # show who connected to us + print ('connection from', client_address) + print (connection) + # receive the data in small chunks and print it + while True: + data = connection.recv(999) + if data: + # output received data + print ("Data: %s" % data.decode()) + connection.sendall(str.encode("We recieved " + str(len(data)) + " bytes from you")) + else: + # no more data -- quit the loop + print ("no more data.") + break + finally: + # Clean up the connection + connection.close() diff --git a/additions/sctp-server/requirements.txt b/additions/sctp-server/requirements.txt new file mode 100644 index 0000000..c9c33e2 --- /dev/null +++ b/additions/sctp-server/requirements.txt @@ -0,0 +1 @@ +pysctp==0.7.2 diff --git a/additions/sctp-server/run.sh b/additions/sctp-server/run.sh new file mode 100755 index 0000000..e93d9c3 --- /dev/null +++ b/additions/sctp-server/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 example.py diff --git a/deploy/kubernetes/manifests/extras/56-mizutest-sctp-server-dep.yaml b/deploy/kubernetes/manifests/extras/56-mizutest-sctp-server-dep.yaml new file mode 100644 index 0000000..aae68dc --- /dev/null +++ b/deploy/kubernetes/manifests/extras/56-mizutest-sctp-server-dep.yaml @@ -0,0 +1,50 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mizutest-sctp-server + labels: + name: mizutest-sctp-server + namespace: sock-shop +spec: + replicas: 1 + selector: + matchLabels: + name: mizutest-sctp-server + template: + metadata: + labels: + name: mizutest-sctp-server + spec: + containers: + - name: mizutest-sctp-server + image: mertyildiran/mizutest-sctp-server:latest + env: + - name: PYTHONUNBUFFERED + value: "1" + - name: PYTHONIOENCODING + value: "UTF-8" + imagePullPolicy: Always + command: ["sh", "-c", "./run.sh"] + resources: + limits: + cpu: 75m + memory: 100Mi + requests: + cpu: 10m + memory: 10Mi + ports: + - containerPort: 50051 + hostPort: 50051 + protocol: SCTP + securityContext: + runAsNonRoot: true + runAsUser: 10001 + capabilities: + drop: + - all + add: + - NET_BIND_SERVICE + readOnlyRootFilesystem: true + nodeSelector: + beta.kubernetes.io/os: linux diff --git a/deploy/kubernetes/manifests/extras/57-mizutest-sctp-server-svc.yaml b/deploy/kubernetes/manifests/extras/57-mizutest-sctp-server-svc.yaml new file mode 100644 index 0000000..7ee85f2 --- /dev/null +++ b/deploy/kubernetes/manifests/extras/57-mizutest-sctp-server-svc.yaml @@ -0,0 +1,19 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: mizutest-sctp-server + annotations: + prometheus.io/scrape: 'true' + labels: + name: mizutest-sctp-server + namespace: sock-shop +spec: + clusterIP: None # Headless + ports: + # the port that this service should serve on + - port: 50051 + targetPort: 50051 + protocol: SCTP + selector: + name: mizutest-sctp-server diff --git a/deploy/kubernetes/manifests/extras/58-mizutest-sctp-client-dep.yaml b/deploy/kubernetes/manifests/extras/58-mizutest-sctp-client-dep.yaml new file mode 100644 index 0000000..34ca0db --- /dev/null +++ b/deploy/kubernetes/manifests/extras/58-mizutest-sctp-client-dep.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mizutest-sctp-client + labels: + name: mizutest-sctp-client + namespace: sock-shop +spec: + replicas: 1 + selector: + matchLabels: + name: mizutest-sctp-client + template: + metadata: + labels: + name: mizutest-sctp-client + spec: + containers: + - name: mizutest-sctp-client + image: mertyildiran/mizutest-sctp-client:latest + env: + - name: PYTHONUNBUFFERED + value: "1" + - name: PYTHONIOENCODING + value: "UTF-8" + imagePullPolicy: Always + command: ["sh", "-c", "./run.sh"] + resources: + limits: + cpu: 75m + memory: 100Mi + requests: + cpu: 10m + memory: 10Mi + ports: + - containerPort: 50051 + securityContext: + runAsNonRoot: true + runAsUser: 10001 + capabilities: + drop: + - all + add: + - NET_BIND_SERVICE + readOnlyRootFilesystem: true + nodeSelector: + beta.kubernetes.io/os: linux diff --git a/deploy/kubernetes/manifests/extras/59-mizutest-sctp-client-svc.yaml b/deploy/kubernetes/manifests/extras/59-mizutest-sctp-client-svc.yaml new file mode 100644 index 0000000..b0ec1c5 --- /dev/null +++ b/deploy/kubernetes/manifests/extras/59-mizutest-sctp-client-svc.yaml @@ -0,0 +1,17 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: mizutest-sctp-client + annotations: + prometheus.io/scrape: 'true' + labels: + name: mizutest-sctp-client + namespace: sock-shop +spec: + ports: + # the port that this service should serve on + - port: 50051 + targetPort: 50051 + selector: + name: mizutest-sctp-client diff --git a/deploy/kubernetes/manifests/extras/60-mizutest-sctp-network-policy.yaml b/deploy/kubernetes/manifests/extras/60-mizutest-sctp-network-policy.yaml new file mode 100644 index 0000000..b2223ac --- /dev/null +++ b/deploy/kubernetes/manifests/extras/60-mizutest-sctp-network-policy.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: kubeshark-hub-network-policy + namespace: sock-shop +spec: + podSelector: + matchLabels: + name: mizutest-sctp-server + policyTypes: + - Ingress + - Egress + ingress: + - ports: + - protocol: SCTP + port: 50051 + egress: + - {}