Kubernetes-Set up Cluster by bash script
项目描述备注Node OSUbuntu18.04Kubernetes1.21.1Node NamecpMasterNode Nameworkerworker说明本脚本参考Linux Foundation关于Kubernetes new Cluster的脚本,并讲源换成ali云,本脚本支持单一Master实验环境Master:#!/bin/bash#/* **************** 2021-
·
环境参数
项目 | 描述 | 备注 |
---|---|---|
Node OS | Ubuntu | 18.04 |
Kubernetes | 1.21.1 | |
Node Name | cp | Master |
Node Name | worker | worker |
说明
- 本脚本参考Linux Foundation关于Kubernetes new Cluster的脚本,并讲源换成ali云,本脚本支持单一Master实验环境
- 使用 bash k8scp.sh | tee $HOME/cp.out命令,保持实验结果,便于找到kubeadm jion信息
- Master:
#!/bin/bash
#/* **************** 2021-12-20 /k8scp.sh **************** */
#/*
# * The code is from: Copyright the Linux Foundation, 2021
# * Chaged By Etaon
# * This Copyright is retained for the purpose of protecting free
# * redistribution of source.
# *
# * URL: https://training.linuxfoundation.org
#
# * email: info@linuxfoundation.org
# 001@etaon.top
# *
# * This code is distributed under Version 2 of the GNU General Public
# * License, which you should have received with the source.
# *
# */
#!/bin/bash -x
## TxS 6-2021
## v1.21.1 CKA/CKAD/CKS
echo "This script is written to work with Ubuntu 18.04"
sleep 3
echo
echo "Disable swap until next reboot"
echo
sudo swapoff -a
echo "Update the local node"
sudo apt-get update && sudo apt-get upgrade -y
echo
echo "Install Docker"
sleep 3
# Set Docker mirrors to aliyun
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-cache madison docker-ce
sudo apt-get install -y docker.io
echo
echo "Install kubeadm, kubelet, and kubectl"
sleep 3
# Set Kubernetes mirrors to aliyun
sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubeadm=1.21.1-00 kubelet=1.21.1-00 kubectl=1.21.1-00
sudo apt-mark hold kubelet kubeadm kubectl
echo
echo "Installed - now to get Calico Project network plugin"
## If you are going to use a different plugin you'll want
## to use a different IP address, found in that plugins
## readme file.
sleep 3
sudo bash <<-'EOF'
#!/bin/bash
images=(
kube-apiserver:v1.21.1
kube-controller-manager:v1.21.1
kube-scheduler:v1.21.1
kube-proxy:v1.21.1
pause:3.4.1
etcd:3.4.13-0
coredns:1.8.0
)
for imageName in ${images[@]} ; do
docker pull registry.aliyuncs.com/google_containers/$imageName
docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.aliyuncs.com/google_containers/$imageName
done
EOF
sudo docker tag k8s.gcr.io/coredns:1.8.0 k8s.gcr.io/coredns/coredns:v1.8.0
## This assumes you are not using 192.168.0.0/16 for your host
sudo kubeadm init --kubernetes-version 1.21.1 --pod-network-cidr 192.168.0.0/16
sleep 5
echo "Running the steps explained at the end of the init output for you"
mkdir -p $HOME/.kube
sleep 2
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sleep 2
sudo chown $(id -u):$(id -g) $HOME/.kube/config
echo "Apply Calico network plugin from ProjectCalico.org"
echo "If you see an error they may have updated the yaml file"
echo "Use a browser, navigate to the site and find the updated file"
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
echo
echo
sleep 3
echo "You should see this node in the output below"
echo "It can take up to a minute for node to show Ready status"
echo
kubectl get node
echo
echo
echo "Script finished. Move to the next step"
- Worker:
#!/bin/bash
#/* **************** LFS260:2021-08-10 s_04/k8sSecond.sh **************** */
#/*
# * The code is from: Copyright the Linux Foundation, 2021
# * Chaged By Etaon
# * This Copyright is retained for the purpose of protecting free
# * redistribution of source.
# *
# * URL: https://training.linuxfoundation.org
#
# * email: info@linuxfoundation.org
# 001@etaon.top
# *
# * This code is distributed under Version 2 of the GNU General Public
# * License, which you should have received with the source.
# *
# */
#!/bin/bash -x
## TxS 06-2021
## CKA/CKAD/CKS for 1.21.1
##
echo " This script is written to work with Ubuntu 18.04"
echo
sleep 3
echo " Disable swap until next reboot"
echo
sudo swapoff -a
echo " Update the local node"
sleep 2
sudo apt-get update && sudo apt-get upgrade -y
echo
sleep 2
# Set Docker mirrors to aliyun
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
echo " Install Docker"
sleep 3
sudo apt-get install -y docker.io
echo
echo " Install kubeadm, kubelet, and kubectl"
sleep 2
# Set Kubernetes mirrors to aliyun
sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubeadm=1.21.1-00 kubelet=1.21.1-00 kubectl=1.21.1-00
sudo apt-mark hold kubelet kubeadm kubectl
echo
echo " Script finished. You now need the kubeadm join command"
echo " from the output on the cp node"
echo
最后worker需要手动加入Cluster
zyi@worker:~$ sudo kubeadm join 192.168.21.110:6443 --token vrg7be.z4f8n71mfgaubqiq --discovery-token-ca-cert-hash sha256:7b0510eff65c6c918a80536ffdd45678b785cba3cc152b31f2ac47e8f5ba8bcf
[preflight] Running pre-flight checks
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
更多推荐
已为社区贡献9条内容
所有评论(0)