aliyun 的Severless Kubernet,无需配置,直接使用。但是还是要自己先熟悉一下过程吧。 接下来把笔记写一下。
本机环境是ubuntu,作为Master,再用VirtualBox 准备两台CentOS7,作为worker。
部署过程参考我的上一篇文章。
https://blog.csdn.net/shelutai/article/details/122606496
角色 | 系统 | IP |
---|---|---|
master | CentOS7 | 192.168.56.9 |
worker1 | CentOS7 | 192.168.56.10 |
worker2 | CentOS7 | 192.168.56.11 |
先配置3台机器免登
ssh-keygen -t rsa -c '[email protected]'
一开始无法直接登录,需要vagrant ssh 命令登录。然后把生成的公钥复制到worker1,worker2 ~/.ssh/authorized_keys,修改三台机器的/etc/hostname为角色名,然后就可以:ssh vagrant@master
** 安装docker所需的工具**
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
配置阿里云的docker源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
指定安装这个版本的docker-ce
docker-ce-cli-18.09.9-3.el7 这个也加上,不然会自动安装高版本的docker命令行。
sudo yum install -y docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7
启动docker
sudo systemctl enable docker && systemctl start docker
关闭防火墙
sudo systemctl disable firewalld &&
sudo systemctl stop firewalld
关闭selinux
临时禁用selinux
sudo setenforce 0
永久关闭 修改/etc/sysconfig/selinux文件设置
sudo sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
sudo sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
禁用交换分区
sudo swapoff -a
永久禁用,打开/etc/fstab注释掉swap那一行。
sudo sed -i 's/.*swap.*/#&/' /etc/fstab
修改内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
注意,这个只在master管理节点
执行配置k8s阿里云源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
安装kubeadm、kubectl、kubelet
yum install -y kubectl-1.16.0-0 kubeadm-1.16.0-0 kubelet-1.16.0-0
启动kubelet服务
systemctl enable kubelet && systemctl start kubelet
看到以下表示成功。
注意事项
kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.16.0 --apiserver-advertise-address 192.168.56.9 --pod-network-cidr=10.244.0.0/16 --token-ttl 0
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.56.9:6443 --token kh16om.442muq0ft8r3w8nb \
--discovery-token-ca-cert-hash sha256:d9f36d2625859cd30b1a4e88071c6ece5759a73b0d66544f8e9c4b5cf8aadad0
如果没有成功,可以清除重来,清除的方法参考:
https://blog.csdn.net/one2threexm/article/details/107735228
初始化后,按照提升,完成:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
记住node加入集群的命令,
上面kubeadm init执行成功后会返回给你node节点加入集群的命令,等会要在node节点上执行,需要保存下来,如果忘记了,可以使用如下命令获取。
kubeadm token create --print-join-command
以上,安装master节点完毕。可以使用kubectl get nodes查看一下,此时master处于NotReady状态,暂时不用管。
安装kubeadm、kubelet在worker1,worker2上操作。
执行配置k8s阿里云源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
安装kubeadm、kubectl、kubelet
yum install -y kubeadm-1.16.0-0 kubelet-1.16.0-0
启动kubelet服务
systemctl enable kubelet && systemctl start kubelet
这里加入集群的命令每个人都不一样,可以登录master节点,使用kubeadm token create --print-join-command 来获取。获取后执行如下。
kubeadm join 192.168.56.9:6443 --token kh16om.442muq0ft8r3w8nb \
--discovery-token-ca-cert-hash sha256:d9f36d2625859cd30b1a4e88071c6ece5759a73b0d66544f8e9c4b5cf8aadad0
出现这个表示加入成功:
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.
加入成功后,可以在master节点上使用kubectl get nodes命令查看到加入的节点。
[root@master vagrant]# kubectl get node
NAME STATUS ROLES AGE VERSION
master.localdomain NotReady master 18m v1.16.0
worker1.localdomain NotReady <none> 2m33s v1.16.0
worker2 NotReady <none> 51s v1.16.0
STATUS 都是NotReady,接下来装fannel
[root@docker-k8s01 ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
如果国内打开不了,请参考:https://blog.csdn.net/weixin_43298522/article/details/109769013
执行完以后,等待一会,master 和worker 会陆续变成“READY”
[root@master vagrant]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master.localdomain Ready master 31m v1.16.0
worker1.localdomain Ready <none> 15m v1.16.0
worker2 NotReady <none> 14m v1.16.0
[root@master vagrant]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master.localdomain Ready master 32m v1.16.0
worker1.localdomain Ready <none> 16m v1.16.0
worker2 Ready <none> 14m v1.16.0
部署完成,撒花吧。
接下来,一起练习吧。
参考:
https://cloud.tencent.com/developer/article/1709491
https://cloud.tencent.com/developer/article/1681998
https://github.com/opsnull/follow-me-install-kubernetes-cluster