From 925c4a6ba072ca8df6fd925d579c08706ea5877b Mon Sep 17 00:00:00 2001 From: Simon Ehrenstein <simon.ehrenstein@gmail.com> Date: Sat, 5 Dec 2020 12:37:37 +0100 Subject: [PATCH] Make kubectl run in proxy mode --- .../random-scheduler/Dockerfile | 7 +++---- .../random-scheduler/schedule.sh | 7 ++++--- .../infrastructure/random-scheduler/test.yaml | 20 ------------------- 3 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 execution/infrastructure/random-scheduler/test.yaml diff --git a/execution/infrastructure/random-scheduler/Dockerfile b/execution/infrastructure/random-scheduler/Dockerfile index fadb231bd..9619d0bac 100644 --- a/execution/infrastructure/random-scheduler/Dockerfile +++ b/execution/infrastructure/random-scheduler/Dockerfile @@ -1,9 +1,8 @@ -FROM ubuntu:bionic +FROM alpine:3.12 -RUN apt-get update -RUN apt-get dist-upgrade +RUN apk update -RUN apt-get install -y curl jq +RUN apk add curl jq bash RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl diff --git a/execution/infrastructure/random-scheduler/schedule.sh b/execution/infrastructure/random-scheduler/schedule.sh index 2eec0f18c..e2e10c0ab 100755 --- a/execution/infrastructure/random-scheduler/schedule.sh +++ b/execution/infrastructure/random-scheduler/schedule.sh @@ -1,7 +1,8 @@ #!/bin/bash -KUBE_API_SERVER=($(kubectl cluster-info | grep 'Kubernetes master' | awk '/http/ {print $NF}' | awk -F : '{print $1$2}' | awk '{ gsub(/\/\//, "://"); print }')) -echo "K8's API server: $KUBE_API_SERVER" +# use kubectl in proxy mode in order to allow curl requesting the k8's api server +kubectl proxy --port 8080 & + echo "Target Namespace: $TARGET_NAMESPACE" while true; do @@ -10,7 +11,7 @@ do NODES=($(kubectl get nodes -o json | jq '.items[].metadata.name' | tr -d '"')) NUMNODES=${#NODES[@]} CHOSEN=${NODES[$[$RANDOM % $NUMNODES]]} - curl --insecure --header "Content-Type:application/json" --request POST --data '{"apiVersion":"v1", "kind": "Binding", "metadata": {"name": "'$PODNAME'"}, "target": {"apiVersion": "v1", "kind": "Node", "name": "'$CHOSEN'"}}' https://10.96.0.1/api/v1/namespaces/$TARGET_NAMESPACE/pods/$PODNAME/binding/ + curl --header "Content-Type:application/json" --request POST --data '{"apiVersion":"v1", "kind": "Binding", "metadata": {"name": "'$PODNAME'"}, "target": {"apiVersion": "v1", "kind": "Node", "name": "'$CHOSEN'"}}' localhost:8080/api/v1/namespaces/$TARGET_NAMESPACE/pods/$PODNAME/binding/ echo "Assigned $PODNAME to $CHOSEN" done sleep 1 diff --git a/execution/infrastructure/random-scheduler/test.yaml b/execution/infrastructure/random-scheduler/test.yaml deleted file mode 100644 index 9104a0968..000000000 --- a/execution/infrastructure/random-scheduler/test.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 -kind: Deployment -metadata: - name: nginx-deployment -spec: - selector: - matchLabels: - app: nginx - replicas: 2 # tells deployment to run 2 pods matching the template - template: - metadata: - labels: - app: nginx - spec: - schedulerName: random-scheduler - containers: - - name: nginx - image: nginx:1.14.2 - ports: - - containerPort: 80 \ No newline at end of file -- GitLab