Advertisement
Guest User

Just Me | Kubernetes LXC Bootstrap

a guest
Dec 13th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Install docker from Docker-ce repository
  4. echo "[TASK 1] Install docker container engine"
  5. yum install -y -q yum-utils device-mapper-persistent-data lvm2 > /dev/null 2>&1
  6. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo > /dev/null 2>&1
  7. yum install -y -q docker-ce-18.06.0.ce-3.el7 >/dev/null 2>&1
  8.  
  9. # Enable docker service
  10. echo "[TASK 2] Enable and start docker service"
  11. systemctl enable docker >/dev/null 2>&1
  12. systemctl start docker
  13.  
  14. # Add yum repo file for Kubernetes
  15. echo "[TASK 3] Add yum repo file for kubernetes"
  16. cat >>/etc/yum.repos.d/kubernetes.repo<<EOF
  17. [kubernetes]
  18. name=Kubernetes
  19. baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
  20. enabled=1
  21. gpgcheck=1
  22. repo_gpgcheck=0
  23. gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
  24. https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
  25. EOF
  26.  
  27. # Install Kubernetes
  28. echo "[TASK 4] Install Kubernetes (kubeadm, kubelet and kubectl)"
  29. yum install -y -q kubeadm-1.17.0 kubelet-1.17.0 kubectl-1.17.0 >/dev/null 2>&1
  30.  
  31. # Start and Enable kubelet service
  32. echo "[TASK 5] Enable and start kubelet service"
  33. systemctl enable kubelet >/dev/null 2>&1
  34. echo 'KUBELET_EXTRA_ARGS="--fail-swap-on=false"' > /etc/sysconfig/kubelet
  35. systemctl start kubelet >/dev/null 2>&1
  36.  
  37. # Install Openssh server
  38. echo "[TASK 6] Install and configure ssh"
  39. yum install -y -q openssh-server >/dev/null 2>&1
  40. sed -i 's/.*PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
  41. systemctl enable sshd >/dev/null 2>&1
  42. systemctl start sshd >/dev/null 2>&1
  43.  
  44. # Set Root password
  45. echo "[TASK 7] Set root password"
  46. echo "kubeadmin" | passwd --stdin root >/dev/null 2>&1
  47.  
  48. # Install additional required packages
  49. echo "[TASK 8] Install additional packages"
  50. yum install -y -q which net-tools sudo sshpass less >/dev/null 2>&1
  51.  
  52. # Hack required for Kubernetes v1.15+
  53. mknod /dev/kmsg c 1 11
  54.  
  55. #######################################
  56. # To be executed only on master nodes #
  57. #######################################
  58.  
  59. if [[ $(hostname) =~ .*master.* ]]
  60. then
  61.  
  62. # Initialize Kubernetes
  63. echo "[TASK 9] Initialize Kubernetes Cluster"
  64. kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all >> /root/kubeinit.log 2>&1
  65.  
  66. # Copy Kube admin config
  67. echo "[TASK 10] Copy kube admin config to root user .kube directory"
  68. mkdir /root/.kube
  69. cp /etc/kubernetes/admin.conf /root/.kube/config
  70.  
  71. # Deploy flannel network
  72. echo "[TASK 11] Deploy flannel network"
  73. kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml > /dev/null 2>&1
  74.  
  75. # Generate Cluster join command
  76. echo "[TASK 12] Generate and save cluster join command to /joincluster.sh"
  77. joinCommand=$(kubeadm token create --print-join-command)
  78. echo "$joinCommand --ignore-preflight-errors=all" > /joincluster.sh
  79.  
  80. fi
  81.  
  82. #######################################
  83. # To be executed only on worker nodes #
  84. #######################################
  85.  
  86. if [[ $(hostname) =~ .*worker.* ]]
  87. then
  88.  
  89. # Join worker nodes to the Kubernetes cluster
  90. echo "[TASK 9] Join node to Kubernetes Cluster"
  91. sshpass -p "kubeadmin" scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no kmaster.lxd:/joincluster.sh /joincluster.sh 2>/tmp/joincluster.log
  92. bash /joincluster.sh >> /tmp/joincluster.log 2>&1
  93.  
  94. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement