Skip to content
Snippets Groups Projects
Commit 925c4a6b authored by Simon Ehrenstein's avatar Simon Ehrenstein
Browse files

Make kubectl run in proxy mode

parent 2217a2f9
No related branches found
No related tags found
1 merge request!61Allow using a random scheduler
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
......
#!/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
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment