Commit 05e6e7df authored by Larkin Heintzman's avatar Larkin Heintzman

ping deployment set up

parent da6817c4
# ROS-Kubernetes # ROS-Kubernetes
<<<<<<< HEAD
Contains scrips and files to create a fielded ros kubernetes cluster. Contains scrips and files to create a fielded ros kubernetes cluster.
# Table of Contents: # Table of Contents:
...@@ -19,12 +18,9 @@ Contains scrips and files to create a fielded ros kubernetes cluster. ...@@ -19,12 +18,9 @@ Contains scrips and files to create a fielded ros kubernetes cluster.
* [Imaging ROS Test](#imaging-ros-test) * [Imaging ROS Test](#imaging-ros-test)
* [Handy Troubleshooting Commands](#handy-troubleshooting-commands) * [Handy Troubleshooting Commands](#handy-troubleshooting-commands)
* [Links With More Information](#links-with-more-information) * [Links With More Information](#links-with-more-information)
=======
Contains scrips and files to create a fielded ros kubernetes cluster. <!-- remote desktop tutorial:
[[_TOC_]] https://www.e2enetworks.com/help/knowledge-base/how-to-install-remote-desktop-xrdp-on-ubuntu-18-04/ -->
ToC
[TOC]
>>>>>>> d0875940780175e3deab768c56dbde948bc0adee
## Image building ## Image building
......
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
IP=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}') IP=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
INTERFACE=$(ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}') INTERFACE=$(ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}')
OLDIFS=$IFS
IFS="." IFS="."
read ip1 ip2 ip3 ip4 <<< "$IP" read ip1 ip2 ip3 ip4 <<< "$IP"
VIP="$ip1.$ip2.$ip3.233" # virtual ip addr VIP="$ip1.$ip2.$ip3.25" # virtual ip addr
IFS=$OLDIFS
sudo swapoff -a # turn off swap memory sudo swapoff -a # turn off swap memory
...@@ -18,20 +20,17 @@ sudo docker run --network host --rm ghcr.io/kube-vip/kube-vip:main manifest pod ...@@ -18,20 +20,17 @@ sudo docker run --network host --rm ghcr.io/kube-vip/kube-vip:main manifest pod
--leaderElection | sudo tee /etc/kubernetes/manifests/vip.yaml --leaderElection | sudo tee /etc/kubernetes/manifests/vip.yaml
# load up endpoint in the config file # load up endpoint in the config file
# apiServerCertSANs:
# controlPlaneEndpoint:
# advertiseAddress:
configFile="kubeadm-config.yaml" configFile="kubeadm-config.yaml"
newIP="$VIP" newIP="$VIP"
key="apiServerCertSANs"
sed -r "s/^(\s*${key}\s*:\s*).*/\1${newIP}/" -i "$configFile"
key="controlPlaneEndpoint" key="controlPlaneEndpoint"
sed -r "s/^(\s*${key}\s*:\s*).*/\1${newIP}/" -i "$configFile" sed -r "s/^(\s*${key}\s*:\s*).*/\1"${newIP}:6443"/" -i "$configFile"
key="advertiseAddress"
sed -r "s/^(\s*${key}\s*:\s*).*/\1${newIP}/" -i "$configFile"
# exit 0 # key1="apiServer"
# key2="advertiseAddress"
# sed -r "s/^(\s*${key1}\s*:\s*${key2}\s*).*/\1${newIP}/" -i "$configFile"
#
# key="apiServerCertSANs"
# sed -r "s/^(\s*${key1}\s*:\s*).*/\1${newIP}/" -i "$configFile"
sudo kubeadm init --config kubeadm-config.yaml --upload-certs sudo kubeadm init --config kubeadm-config.yaml --upload-certs
...@@ -46,11 +45,31 @@ sudo cp -f /etc/kubernetes/admin.conf $HOME/.kube/config ...@@ -46,11 +45,31 @@ sudo cp -f /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f flannel.yml kubectl apply -f flannel.yml
kubectl taint nodes --all node-role.kubernetes.io/master-
# create control-plane join command and copy it to clip # create control-plane join command and copy it to clip
OLDIFS=$IFS
IFS=''
ifCMD="ip route get 8.8.8.8 | awk -F'dev ' 'NR==1{split(\$2,a,\" \");print a[1]}'"
vipCMD="sudo docker run --network host --rm ghcr.io/kube-vip/kube-vip:main manifest pod --vip "$VIP" \
--interface wlan0 \
--arp \
--controlplane \
--leaderElection | sudo tee /etc/kubernetes/manifests/vip.yaml"
# echo $(/bin/bash -c "$ifCMD")
# echo $(/bin/bash -c "$vipCMD")
IFS=$OLDIFS
echo "------------------------------------------" echo "------------------------------------------"
newKey=$(sudo kubeadm init phase upload-certs --upload-certs | sed -n '3~0p') newKey=$(sudo kubeadm init phase upload-certs --upload-certs | sed -n '3~0p')
echo "$(kubeadm token create --print-join-command) --control-plane --certificate-key $newKey" | xclip -sel clip
# create vip.yaml in manifests of new control plane
# echo "$(ip route get 8.8.8.8 | awk -F"dev " 'NR==1{split($2,a," ");print a[1]}')"
# was working here
echo "$vipCMD && sudo $(kubeadm token create --print-join-command) --control-plane --certificate-key $newKey" | xclip -sel clip
echo "..."
echo "Done starting cluster, control-plane join command is copied, don't forget to move load-balancer virtual ip yaml over to new nodes"
exit 0 exit 0
FROM alpine:3 # FROM alpine:3
FROM bash:latest
RUN apk update && apk upgrade && apk add --no-cache jq
COPY ping.sh / COPY ping.sh /
HEALTHCHECK --interval=5s --timeout=3s \ # health check runs grep command every 10 seconds and registers container as unhealthy if it takes longer than 3 seconds or ping is not running
CMD ps aux | grep '[s]h ping' || exit 1 HEALTHCHECK --interval=10s --timeout=3s --start-period=5s \
CMD ps aux | grep '[s]h ping' || exit 1
#CMD ["sh", "ping"]
# CMD ["/bin/sh"]
#!/bin/bash
echo ping ${HOSTNAME:=localhost} every ${TIMEOUT:=300} sec
while true; do ping -c 1 ${HOSTNAME}; sleep ${TIMEOUT}; done;
#!/bin/sh #!/usr/local/bin/bash
echo ping ${HOSTNAME:=localhost} every ${TIMEOUT:=5} sec
while true; do ping -c 1 ${HOSTNAME}; sleep ${TIMEOUT}; done; # endpoints="localhost" filename="/home/llh/pingstats.json"
if test -f "$filename"; then
echo "file $filename already exists."
else
touch "$filename"
echo "{}" > "$filename"
fi
if [[ -n "$nfsFilename" ]]; then
if test -f "$nfsFilename"; then
echo "NFS file $nfsFilename already exists."
else
touch "$nfsFilename"
echo "{}" > "$nfsFilename"
fi
fi
echo ping "${endpoints} every ${downtime:=3} sec, saving to ${filename}"
# for endpoints in "${endpoints[@]}"; do
# done
# --------------------------------------
while true; do
# for endpoints in "${endpoints[@]}"; do
# echo pinging "${endpoints} now ..."
newData=$(ping -c 3 ${endpoints:=localhost} | tail -n 1)
# if nothing comes back, we dont write anything
if [[ -n "$newData" ]]; then
false
echo "$newData"
else
echo "${endpoints} might be unreachable"
continue
fi
OLDIFS=$IFS
IFS=" "
read bit1 bit2 bit3 bit4 bit5 <<< "$newData"
IFS="/"
read num1 num2 num3 num4 <<< "$bit4"
IFS=$OLDIFS
if test -f "$filename"; then
false
else
touch "$filename"
echo "{}" > "$filename"
fi
echo "debugging:"
echo $num1
echo $num2
echo $num3
echo $num4
# keep a diary
if [[ -n "$num4" ]]; then
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$target][$timedate] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
else
jq --arg timedate $(date +"%H:%M_%F") --arg target $endpoints --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 '.[$target][$timedate] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax}]' "$filename" > "$filename.tmp" && mv "$filename.tmp" "$filename"
fi
# write home about it (if connected)
if [[ -n "$nfsFilename" ]]; then
if [[ -n "$num4" ]]; then
jq --arg timedate $(date +"%H:%M_%F") --arg hostname $HOSTNAME --arg target $endpoints --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 --argjson stdDev $num4 '.[$hostname][$target][$timedate] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax,"std":$stdDev}]' "$nfsFilename" > "$nfsFilename.tmp" && mv "$nfsFilename.tmp" "$nfsFilename"
else
jq --arg timedate $(date +"%H:%M_%F") --arg hostname $HOSTNAME --arg target $endpoints --argjson rttMin $num1 --argjson rttAvg $num2 --argjson rttMax $num3 '.[$hostname][$target][$timedate] += [{"min":$rttMin,"avg":$rttAvg,"max":$rttMax}]' "$nfsFilename" > "$nfsFilename.tmp" && mv "$nfsFilename.tmp" "$nfsFilename"
fi
fi
# done
sleep ${downtime:=3}
done
if test -f "$filename.tmp"; then
rm "$filename.tmp"
fi
if test -f "$nfsFilename.tmp"; then
rm "$nfsFilename.tmp"
fi
# kubeadm-config.yaml # kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta2 apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration kind: ClusterConfiguration
kubernetesVersion: v1.23.4 kubernetesVersion: v1.24.0
# gets set by startup # gets set by startup
controlPlaneEndpoint: 192.168.1.233 controlPlaneEndpoint: 192.168.1.25:6443
networking: networking:
podSubnet: "10.244.0.0/16" podSubnet: "10.244.0.0/16"
# gets set by startup # api:
apiServerCertSANs: 192.168.1.233 # advertiseAddress: "192.168.1.233"
# bindPort: 6443
apiServer: # apiServerCertSANs:
# gets set by startup # - "192.168.1.233"
advertiseAddress: 192.168.1.233
bindPort: 6443
--- ---
kind: KubeletConfiguration kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1 apiVersion: kubelet.config.k8s.io/v1beta1
......
...@@ -18,33 +18,40 @@ spec: ...@@ -18,33 +18,40 @@ spec:
app: cluster app: cluster
spec: spec:
hostname: service-ping hostname: service-ping
tolerations:
- key: "node-role.kubernetes.io/master"
effect: "NoSchedule"
operator: "Exists"
- key: "node-role.kubernetes.io/control-plane"
effect: "NoSchedule"
operator: "Exists"
volumes:
- name: ping-storage
hostPath:
path: /home/llh/pingStats
terminationGracePeriodSeconds: 3
containers: containers:
- name: ping - name: ping
securityContext: securityContext:
privileged: true privileged: true
image: pinga/llh:v0 # image: doorbell:latest
command: ["/bin/sh"] # You need to run some task inside a volumeMounts:
- name: ping-storage
mountPath: /tmp/pingStats
image: localhost:5000/doorbell:latest
imagePullPolicy: Always
command: ["/usr/local/bin/bash"] # You need to run some task inside a
args: ["-c", "/ping.sh & while true; do sleep 10; done;"] # Our simple program just sleeps inside args: ["-c", "/ping.sh & while true; do sleep 10; done;"] # Our simple program just sleeps inside
# args: ["-c", "/ping.sh" & while true; do sleep 10; done;"] # Our simple program just sleeps inside
# args: ["-c", "./ping.sh"] # Our simple program just sleeps inside
env:
- name: endpoints
value: "localhost"
- name: filename
value: "/tmp/pingStats/pingStats.json"
ports: ports:
- containerPort: 11311 - containerPort: 11311
name: pingport name: pingport
nodeSelector: nodeSelector:
kubernetes.io/hostname: sentinel kubernetes.io/hostname: pop-os # to run on control plane
# kubernetes.io/hostname: pop-os # to run on control plane # kubernetes.io/hostname: sentinel
# ---
#
# apiVersion: v1
# kind: Service
# metadata:
# name: service-ping
# labels:
# app: cluster
# node: ping
# spec:
# selector:
# app: cluster
# node: ping
# clusterIP: None
# ports:
# - port: 11311
# name: ping
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment