From e62fb5875eea8ca14310abdc0c0e7f0e5f5a7ad0 Mon Sep 17 00:00:00 2001 From: JJGadgets Date: Fri, 22 Dec 2023 00:52:59 +0800 Subject: [PATCH] fix(tasks/iperf2): headless svc, pod-ready --- .taskfiles/k8s/Taskfile.dist.yaml | 28 ++++++++++++++++++---- .taskfiles/k8s/template/iperf2/client.yaml | 7 ++++-- .taskfiles/k8s/template/iperf2/server.yaml | 17 +++++++------ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.taskfiles/k8s/Taskfile.dist.yaml b/.taskfiles/k8s/Taskfile.dist.yaml index ac650dd8..9d94248f 100644 --- a/.taskfiles/k8s/Taskfile.dist.yaml +++ b/.taskfiles/k8s/Taskfile.dist.yaml @@ -25,17 +25,35 @@ tasks: NAME: &name-fail '{{ or .NAME (fail "Missing `NAME` environment variable!") }}' NS: *ns-fail cmds: - - until [[ $(kubectl -n "{{.NS}}" get pod "{{.NAME}}" -o jsonpath='{.items[*].status.phase}') == "Pending" ]]; do sleep 1; done + - until [[ $(kubectl -n {{.NS}} get pod {{.NAME}} -o jsonpath='{.items[*].status.phase}') == "Pending" ]]; do sleep 1; done wait-pod-running: aliases: [waitr] internal: true - desc: Wait for a job's pod to change its status to pending + desc: Wait for a job's pod to change its status to running vars: NAME: *name-fail NS: *ns-fail cmds: - - until [[ $(kubectl -n "{{.NS}}" get pod "{{.NAME}}" -o jsonpath='{.items[*].status.phase}') == "Running" ]]; do sleep 1; done + - until [[ $(kubectl -n {{.NS}} get pod {{.NAME}} -o jsonpath='{.items[*].status.phase}') == "Running" ]]; do sleep 1; done + + wait-pod-running-v2: + internal: true + desc: Wait for a job's pod to change its status to running + vars: + NAME: *name-fail + NS: *ns-fail + cmds: + - until kubectl wait pod -n {{.NS}} {{.NAME}} --for-jsonpath='{.items[*].status.phase}'=Running --timeout=-; do sleep 1; done + + wait-pod-ready: + internal: true + desc: Wait for a pod to be ready + vars: + NAME: *name-fail + NS: *ns-fail + cmds: + - until kubectl wait pod -n {{.NS}} {{.NAME}} --for=condition=Ready --timeout=1h; do sleep 1; done wait-pod-delete: aliases: [waitd] @@ -147,7 +165,7 @@ tasks: cmds: - cat ./server.yaml | envsubst | kubectl apply -f - - defer: cat ./server.yaml | envsubst | kubectl delete -f - - - task: wait-pod-running + - task: wait-pod-ready vars: NAME: '-l job-name={{.SERVER_NAME}}' NS: '{{.SERVER_NS}}' @@ -241,4 +259,4 @@ tasks: - |- # resume Flux Kustomization [[ {{.KS}} != "disabled" ]] && flux resume kustomization -n {{.KSNS}} {{.KS}} || true - |- # remove reason annotation from Flux Kustomization - [[ {{.KS}} != "disabled" ]] && kubectl annotate kustomizations.kustomize.toolkit.fluxcd.io -n {{.KSNS}} {{.KS}} scaledown.home.arpa/reason- || true \ No newline at end of file + [[ {{.KS}} != "disabled" ]] && kubectl annotate kustomizations.kustomize.toolkit.fluxcd.io -n {{.KSNS}} {{.KS}} scaledown.home.arpa/reason- || true diff --git a/.taskfiles/k8s/template/iperf2/client.yaml b/.taskfiles/k8s/template/iperf2/client.yaml index c255e697..6d499f3d 100644 --- a/.taskfiles/k8s/template/iperf2/client.yaml +++ b/.taskfiles/k8s/template/iperf2/client.yaml @@ -12,7 +12,10 @@ spec: spec: automountServiceAccountToken: false restartPolicy: Never - nodeName: ${CLIENT_NODE} + # hostNetwork: true + dnsPolicy: "ClusterFirstWithHostNet" + nodeSelector: + kubernetes.io/hostname: "${CLIENT_NODE}" containers: - name: *name image: public.ecr.aws/debian/debian:bookworm-20230411-slim @@ -46,4 +49,4 @@ spec: matchLabels: job-name: "${SERVER_NAME}" ports: - - port: 5001 \ No newline at end of file + - port: 5001 diff --git a/.taskfiles/k8s/template/iperf2/server.yaml b/.taskfiles/k8s/template/iperf2/server.yaml index 665e858b..88f0166d 100644 --- a/.taskfiles/k8s/template/iperf2/server.yaml +++ b/.taskfiles/k8s/template/iperf2/server.yaml @@ -12,7 +12,9 @@ spec: spec: automountServiceAccountToken: false restartPolicy: "Never" - nodeName: "${SERVER_NODE}" + nodeSelector: + kubernetes.io/hostname: "${SERVER_NODE}" + # hostNetwork: true containers: - name: *name image: "public.ecr.aws/debian/debian:bookworm-20230411-slim" @@ -50,13 +52,14 @@ metadata: jobs.home.arpa/iperf2: "server" spec: type: ClusterIP + clusterIP: "None" selector: job-name: *name - ports: - - name: "iperf" - protocol: "TCP" - port: &port ${SERVER_PORT} - targetPort: *port + # ports: + # - name: "iperf" + # protocol: "TCP" + # port: &port ${SERVER_PORT} + # targetPort: *port --- apiVersion: networking.k8s.io/v1 kind: NetworkPolicy @@ -83,4 +86,4 @@ spec: egress: - to: - ipBlock: - cidr: "0.0.0.0/0" \ No newline at end of file + cidr: "0.0.0.0/0"