Skip to content

Commit

Permalink
Merge pull request #2 from mattmattox/manager-worker
Browse files Browse the repository at this point in the history
adding manager and worker
  • Loading branch information
mattmattox authored Sep 7, 2020
2 parents a32cc97 + 1fa82ba commit bfae674
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 12 deletions.
Binary file removed kubectl
Binary file not shown.
3 changes: 1 addition & 2 deletions Dockerfile → manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ RUN apt-get update && apt-get install -yq --no-install-recommends \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

## Install kubectl
ADD kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl
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" && chmod u+x kubectl && mv kubectl /usr/local/bin/kubectl

## Setup run script
WORKDIR /root
Expand Down
19 changes: 9 additions & 10 deletions run.sh → manager/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

if [[ -z $NODE_TIMEOUT ]]
if [[ -z $nodeTimeout ]]
then
NODE_TIMEOUT=360
nodeTimeout=360
fi
echo "Node timeout: $NODE_TIMEOUT"
echo "nodeTimeout: $nodeTimeout"

if [[ -z $AUTO_UNCORDON ]]
then
Expand Down Expand Up @@ -35,7 +35,6 @@ do
echo "#########################################################"
echo "Checking $node"
current_status="$(kubectl get --no-headers $node | awk '{print $2}')"
##echo "Current node status: $current_status"
if [[ "$current_status" == "Ready" ]] || [[ "$current_status" == "Ready,SchedulingDisabled" ]]
then
echo "$node is ready"
Expand Down Expand Up @@ -73,7 +72,7 @@ do
mv ~/drained_nodes.tmp ~/drained_nodes
break
fi
if [ $count -gt $NODE_TIMEOUT ]
if [ $count -gt $nodeTimeout ]
then
echo "$node has been down for greater than 5Mins, assuming node is down for good."
echo "Starting drain of node..."
Expand Down Expand Up @@ -113,11 +112,11 @@ do
while ! kubectl get pods -n cattle-system | grep ^'cattle-cluster-agent-' | awk '{print $3}' | grep "Running"
do
sleep 1
cattlecount=$((cattlecount+1))
if [ $cattlecount -gt 60 ]
then
break
fi
cattlecount=$((cattlecount+1))
if [ $cattlecount -gt 60 ]
then
break
fi
done
echo "Scaling back down to 1..."
kubectl scale --replicas=1 deployment/cattle-cluster-agent -n cattle-system
Expand Down
20 changes: 20 additions & 0 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:18.04

MAINTAINER [email protected]

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -yq --no-install-recommends \
apt-utils \
curl \
docker-ce-cli \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

## Install kubectl
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" && chmod u+x kubectl && mv kubectl /usr/local/bin/kubectl

## Setup run script
WORKDIR /root
ADD run.sh /root/run.sh

CMD /root/run.sh
69 changes: 69 additions & 0 deletions worker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

function check_node {
current_status=`kubectl get node --no-headers "$1" |awk '{print $2}'`
if [[ "$current_status" == "Ready" ]] || [[ "$current_status" == "Ready,SchedulingDisabled" ]]
then
return 0
else
return 1
fi
}

if [[ -z $nodeTimeout ]]
then
nodeTimeout=60
fi
echo "nodeTimeout: $nodeTimeout"

echo "nodeName: $nodeName"
if [[ -z "$nodeName" ]]
then
echo "Missing nodeName"
exit 1
fi

echo "Verifing Docker CLI access..."
if ! docker info
then
echo "Problem accessing Docker CLI"
exit 2
fi

while true;
do
echo "Checking node status..."
if check_node $nodeName
then
echo "Node is ready"
else
echo "Node is Not ready, rechecking..."
count=0
while true
do
if ! check_node $nodeName
then
echo "Sleeping for $count seconds"
sleep 1
count=$((count+1))
else
echo "Node is now ready"
break
fi
if [ $count -gt $nodeTimeout ]
then
echo "Node has been down for greater then $nodeTimeout seconds, assuming node is down"
echo "Attempting node recovery"
echo "Restarting kubelet"
docker restart kubelet
echo "Sleeping..."
sleep 15
if check_node $nodeName
then
echo "Node has recovered"
break
fi
fi
done
fi
done

0 comments on commit bfae674

Please sign in to comment.