diff --git a/clr-k8s-examples/create_stack.sh b/clr-k8s-examples/create_stack.sh index f71c287..be51645 100755 --- a/clr-k8s-examples/create_stack.sh +++ b/clr-k8s-examples/create_stack.sh @@ -6,75 +6,126 @@ set -o nounset CUR_DIR=$(pwd) SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" -cd $SCRIPT_DIR -function finish { - cd $CUR_DIR +function print_usage_exit() { + echo $"Usage: $0 [minimal|all]" + exit 1 +} + +function finish() { + cd $CUR_DIR } trap finish EXIT -#This only works with kubernetes 1.12+. The kubeadm.yaml is setup -#to enable the RuntimeClass featuregate -sudo -E kubeadm init --config=./kubeadm.yaml +function cluster_init() { + #This only works with kubernetes 1.12+. The kubeadm.yaml is setup + #to enable the RuntimeClass featuregate + sudo -E kubeadm init --config=./kubeadm.yaml -# If this an interactive terminal then wait for user to join workers -if [ -t 0 ]; then -read -p "Join other nodes. Press enter to continue" + # If this an interactive terminal then wait for user to join workers + if [ -t 0 ]; then + read -p "Join other nodes. Press enter to continue" + fi + + rm -rf $HOME/.kube + mkdir -p $HOME/.kube + sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config + sudo chown $(id -u):$(id -g) $HOME/.kube/config + + #Ensure single node k8s works + if [ $(kubectl get nodes | wc -l) -eq 2 ]; then + kubectl taint nodes --all node-role.kubernetes.io/master- + fi +} + +function runtimeclass_kata() { + #Add support for kata runtime + kubectl apply -f 8-kata/runtimeclass_crd.yaml + while [[ $(kubectl get crd runtimeclasses.node.k8s.io >/dev/null 2>&1) || $? -ne 0 ]]; do + echo "Waiting for runtime class CRD" + sleep 2 + done + kubectl apply -f 8-kata/kata-runtimeClass.yaml +} + +function cni() { + kubectl apply -f 0-canal/rbac.yaml + kubectl apply -f 0-canal/canal.yaml +} + +function metrics() { + kubectl apply -f 1-core-metrics/ +} + +function storage() { + #Start rook before any other component that requires storage + ROOK_URL=7-rook + kubectl apply -f ${ROOK_URL}/000-operator.yaml + while [[ $(kubectl get crd clusters.ceph.rook.io pools.ceph.rook.io >/dev/null 2>&1) || $? -ne 0 ]]; do + echo "Waiting for Rook CRDs" + sleep 2 + done + kubectl apply -f ${ROOK_URL}/001-cluster.yaml + kubectl apply -f ${ROOK_URL}/002-storageclass.yaml +} + +function monitoring() { + #Just to allow the CRD to be created. Ideally wait and then run second time + kubectl apply -f 4-kube-prometheus/ + while [[ $(kubectl get crd alertmanagers.monitoring.coreos.com prometheuses.monitoring.coreos.com prometheusrules.monitoring.coreos.com servicemonitors.monitoring.coreos.com >/dev/null 2>&1) || $? -ne 0 ]]; do + echo "Waiting for Prometheus CRDs" + sleep 2 + done + kubectl apply -f 4-kube-prometheus/ + + #Expose the dashboards + #kubectl --namespace monitoring port-forward svc/prometheus-k8s 9090 & + #kubectl --namespace monitoring port-forward svc/grafana 3000 & + #kubectl --namespace monitoring port-forward svc/alertmanager-main 9093 & +} + +function miscellaneous() { + kubectl apply -f 2-dashboard/ + kubectl apply -f 3-efk/ + #Create an ingress load balancer + kubectl apply -f 5-ingres-lb/ + + #Create a bare metal load balancer. + #kubectl apply -f 6-metal-lb/metallb.yaml + + #The config map should be properly modified to pick a range that can live + #on this subnet behind the same gateway (i.e. same L2 domain) + #kubectl apply -f 6-metal-lb/example-layer2-config.yaml +} + +function minimal() { + cluster_init + runtimeclass_kata + cni + metrics +} + +function all() { + minimal + storage + monitoring + miscellaneous +} + +cd $SCRIPT_DIR +if [[ "$#" -eq 0 ]]; then + all + exit fi -rm -rf $HOME/.kube -mkdir -p $HOME/.kube -sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config -sudo chown $(id -u):$(id -g) $HOME/.kube/config - -#Add support for kata runtime -kubectl apply -f 8-kata/runtimeclass_crd.yaml -while [[ $(kubectl get crd runtimeclasses.node.k8s.io > /dev/null 2>&1) || $? -ne 0 ]]; -do echo "Waiting for runtime class CRD"; sleep 2; done -kubectl apply -f 8-kata/kata-runtimeClass.yaml - -kubectl apply -f 0-canal/rbac.yaml -kubectl apply -f 0-canal/canal.yaml - -#Ensure single node k8s works -if [ $(kubectl get nodes | wc -l) -eq 2 ]; then -kubectl taint nodes --all node-role.kubernetes.io/master- -fi - -#Start rook before any other component that requires storage -ROOK_URL=7-rook -kubectl apply -f ${ROOK_URL}/000-operator.yaml -while [[ $(kubectl get crd clusters.ceph.rook.io pools.ceph.rook.io > /dev/null 2>&1) || $? -ne 0 ]]; -do echo "Waiting for Rook CRDs"; sleep 2; done -kubectl apply -f ${ROOK_URL}/001-cluster.yaml -kubectl apply -f ${ROOK_URL}/002-storageclass.yaml - -kubectl apply -f 1-core-metrics/ - -kubectl apply -f 2-dashboard/ - -kubectl apply -f 3-efk/ - -#Just to allow the CRD to be created. Ideally wait and then run second time -kubectl apply -f 4-kube-prometheus/ -while [[ $(kubectl get crd alertmanagers.monitoring.coreos.com prometheuses.monitoring.coreos.com prometheusrules.monitoring.coreos.com servicemonitors.monitoring.coreos.com > /dev/null 2>&1) || $? -ne 0 ]]; -do echo "Waiting for Prometheus CRDs"; sleep 2; done -kubectl apply -f 4-kube-prometheus/ -#Create an ingress load balancer -kubectl apply -f 5-ingres-lb/ - - -#Create a bare metal load balancer. -#kubectl apply -f 6-metal-lb/metallb.yaml - -#The config map should be properly modified to pick a range that can live -#on this subnet behind the same gateway (i.e. same L2 domain) -#kubectl apply -f 6-metal-lb/example-layer2-config.yaml - - -#Expose the dashboards -#kubectl --namespace monitoring port-forward svc/prometheus-k8s 9090 & -#kubectl --namespace monitoring port-forward svc/grafana 3000 & -#kubectl --namespace monitoring port-forward svc/alertmanager-main 9093 & -#kubectl proxy & - +case "$1" in +minimal) + minimal + ;; +all) + all + ;; +*) + print_usage_exit + ;; +esac diff --git a/clr-k8s-examples/reset_stack.sh b/clr-k8s-examples/reset_stack.sh index b86e209..77a5118 100755 --- a/clr-k8s-examples/reset_stack.sh +++ b/clr-k8s-examples/reset_stack.sh @@ -14,7 +14,6 @@ for pod in $(sudo crictl pods --quiet); do sudo crictl rmp "$pod" done - #Forcefull cleanup all artifacts #This is needed is things really go wrong sudo systemctl stop kubelet @@ -45,4 +44,3 @@ sudo systemctl restart crio sudo systemctl restart kubelet sudo -E kubeadm reset -f --cri-socket="/var/run/crio/crio.sock" - diff --git a/clr-k8s-examples/setup_system.sh b/clr-k8s-examples/setup_system.sh index df37027..3104225 100755 --- a/clr-k8s-examples/setup_system.sh +++ b/clr-k8s-examples/setup_system.sh @@ -35,7 +35,7 @@ EOT hostcount=$(grep '127.0.0.1 localhost' /etc/hosts | wc -l) if [ "$hostcount" == "0" ]; then - echo "127.0.0.1 localhost `hostname`" | sudo bash -c "cat >> /etc/hosts" + echo "127.0.0.1 localhost $(hostname)" | sudo bash -c "cat >> /etc/hosts" else echo "/etc/hosts already configured" fi @@ -67,7 +67,7 @@ if [[ ${http_proxy} ]] || [[ ${HTTP_PROXY} ]]; then services=('crio' 'kubelet') for s in "${services[@]}"; do sudo mkdir -p "/etc/systemd/system/${s}.service.d/" - cat << EOF | sudo bash -c "cat > /etc/systemd/system/${s}.service.d/proxy.conf" + cat < /etc/systemd/system/${s}.service.d/proxy.conf" [Service] Environment="HTTP_PROXY=${http_proxy}" Environment="HTTPS_PROXY=${https_proxy}"