####环境
system | cpu | mem | ip | role |
---|---|---|---|---|
centos7.3mini | 8core | 8G | 172.16.1.126 | mster |
centos7.3mini | 8core | 8G | 172.16.1.127 | node01 |
centos7.3mini | 8core | 8G | 172.16.1.128 | node02 |
一.socket5代理配置
配置成脚本socket.sh方便开启关闭,开启socket.sh create && socket.sh start,停止socket.sh stop
1 |
|
二,基础环境配置(master和所有node节点)
配置yum代理
1
echo "proxy=http:127.0.0.1:8118" >>/etc/yum.conf
关闭防火墙
1
systemctl disable firewalld && systemctl stop firewalld
关闭selinux
1
sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config && setenforce 0
关闭swap内存
1
swapoff -a && sed -i s/\/dev\/mapper/cl-swap/#\/dev\/mapper/cl-swap/ /etc/fstab
调整内核参数
1
2
3
4cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF重启机器
三. 安装docker kubelet kubeadm kubectl(master和所有node节点)
配置阿里云yum源 安装docker
1
yum install wget -y && rm -f /etc/yum.repo.d/Cent* && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && yum install vim net-tools docker -y
配置docker 代理
1
2
3
4
5mkdir -p /etc/systemd/system/docker.service.d/
cat <<EFO > /etc/systemd/system/docker.service.d/https-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:8118" "NO_PROXY=localhost,172.16.0.0/16,127.0.0.1,10.244.0.0/16"
EOF启动docker
1
systemctl restart docker
配置kubernetes源
1
2
3
4
5
6
7
8
9cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF安装kubelet kubeadm kubectl并启动kubelet
1
yum install kubelet kubeadm kubectl -y && systemctl enable kubelet && systemctl start kubelet
初始化k8s集群(master)
这一步非常重要,多少人部署k8s就是卡在这一步,好在我已经有了解决办法,提供给大家方便你我他
- 手动下载谷歌镜像(如果你的代理给你可以省略这一步)
1
2
3
4
5
6
7
8
9
10K8S1.9.2对应的镜像版本
gcr.io/google_containers/kube-proxy-amd64 v1.9.2 e6754bb0a529 2 weeks ago 109.1 MB
gcr.io/google_containers/kube-controller-manager-amd64 v1.9.2 769d889083b6 2 weeks ago 137.8 MB
gcr.io/google_containers/kube-apiserver-amd64 v1.9.2 7109112be2c7 2 weeks ago 210.4 MB
gcr.io/google_containers/kube-scheduler-amd64 v1.9.2 2bf081517538 2 weeks ago 62.71 MB
gcr.io/google_containers/etcd-amd64 3.1.11 59d36f27cceb 9 weeks ago 193.9 MB
gcr.io/google_containers/k8s-dns-sidecar-amd64 1.14.7 db76ee297b85 3 months ago 42.03 MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64 1.14.7 5d049a8c4eec 3 months ago 50.27 MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 1.14.7 5feec37454f4 3 months ago 40.95 MB
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 21 months ago 746.9 kB
1 | docker仓库已经有人在同步google的镜像,所以只需要pull下来再tag为上面的名字就好了,批量脚本 |
通过kubectl init 初始化集群
1
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.16.1.126
初始化完成会显示其他node加入群集的命令
1
kubeadm join --token c16280.dbb6f9aeb16f7b2c 172.16.1.126:6443 --discovery-token-ca-cert-hash sha256:706fece558d0e89dcffc4507aef21a35a571cb5263cd522d6505d4b887c53b61
添加K8S 配置和配置kubectl命令补全
1
2
3export KUBECONFIG=/etc/kubernetes/admin.conf
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
echo "source <(kubectl completion bash)" >> ~/.bashrc安装flannel网络
1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
node 节点加入集群(node)
- node节点加入集群时也要下载谷歌镜像,为了避免网络原因造成的加入集群失败,重复上面master下载谷歌镜像的步骤
- 加入集群
1
2
3kubeadm join --token c16280.dbb6f9aeb16f7b2c 172.16.1.126:6443 --discovery-token-ca-cert-hash sha256:706fece558d0e89dcffc4507aef21a35a571cb5263cd522d6505d4b887c53b61
顺利的话会看到下面提醒,
Run 'kubectl get nodes' on the master to see this node join the cluster.
验证集群(master)
验证node状态
1
2
3
4
5[root@k8s-master scripts]# kubectl get no
NAME STATUS ROLES AGE VERSION
k8n1 Ready <none> 2d v1.9.2
k8n2 Ready <none> 2d v1.9.2
localhost.localdomain NotReady master 2d v1.9.2验证整个集群组件状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14[root@k8s-master scripts]# kubectl --namespace=kube-system get pod
NAME READY STATUS RESTARTS AGE
etcd-localhost.localdomain 1/1 Running 0 2d
kube-apiserver-localhost.localdomain 1/1 Running 5 2d
kube-controller-manager-localhost.localdomain 1/1 Running 0 2d
kube-dns-6f4fd4bdf-jsw7w 3/3 Running 0 3h
kube-dns-6f4fd4bdf-xbnkq 3/3 Running 0 2d
kube-flannel-ds-d8xq5 1/1 Running 0 2d
kube-flannel-ds-lsjgq 1/1 Running 2 2d
kube-flannel-ds-wck6c 1/1 Running 0 2d
kube-proxy-8z582 1/1 Running 0 2d
kube-proxy-h58t4 1/1 Running 0 2d
kube-proxy-rh7ml 1/1 Running 2 2d
kube-scheduler-localhost.localdomain 1/1 Running 0 2d
- 本文作者: ChuLinx
- 本文链接: http://yoursite.com/2019/11/30/kubeadm 安装kubernetes 1.9.2全讲解/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!