kubeadm安装kubernetes-v1.13.1
centos虚拟机使用kubeadm安装k8s-v1.13.1。
机器信息如下:
主机名 | ip |
---|---|
master | 192.168.239.200 |
node1 | 192.168.239.201 |
node2 | 192.168.239.202 |
环境准备
设置主机名
192.168.239.200 master
192.168.239.201 node1
192.168.239.202 node2
关闭swap
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭selinux
setenforce 0
配置相关参数
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
vm.swappiness=0
sysctl -p
docker安装
安装docker的yum源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
查看docker版本
yum list docker-ce.x86_64 --showduplicates |sort -r
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 @docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
安装docker
yum install -y --setopt=obsoletes=0 docker-ce-18.06.1.ce-3.el7
systemctl start docker
systemctl enable docker
安装kubeadm等
配置阿里云源
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
node结点不用安装kubectl
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet
安装master结点
国内无法访问google的镜像源,需要自己生成放到docker hub。
如何自己生成镜像放到docker hub请看Docker Hub上自动制做Docker镜像
下载自己生成的镜像源
vim pull-kube-image.sh
#!/bin/bash
images=(kube-scheduler:v1.13.1
kube-proxy:v1.13.1
kube-controller-manager:v1.13.1
kube-apiserver:v1.13.1
pause:3.1
coredns:1.2.6
etcd:3.2.24)
for imagename in ${images[@]}; do
docker pull mathlsj/$imagename
docker tag mathlsj/$imagename k8s.gcr.io/$imagename
docker rmi mathlsj/$imagename
done
docker pull quay.io/coreos/flannel:v0.10.0-amd64
查看镜像源
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-scheduler v1.13.1 9bf9c8fb24af 7 days ago 79.6MB
k8s.gcr.io/kube-proxy v1.13.1 6fbfd87ede1f 7 days ago 80.2MB
k8s.gcr.io/kube-controller-manager v1.13.1 f5e8b3a9a6bf 7 days ago 146MB
k8s.gcr.io/kube-apiserver v1.13.1 14219a09a24c 7 days ago 181MB
k8s.gcr.io/pause 3.1 68112c580347 8 days ago 742kB
k8s.gcr.io/coredns 1.2.6 75ca836e805a 8 days ago 40MB
k8s.gcr.io/etcd 3.2.24 c10486f7ea38 9 days ago 220MB
k8s.gcr.io/kubernetes-dashboard-amd64 v1.8.3 0c60bcf89900 11 months ago 102MB
quay.io/coreos/flannel v0.10.0-amd64 f0fad859c909 11 months ago 44.6MB
节点初始化
kubeadm init --kubernetes-version=v1.13.1 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.239.200
看到Your Kubernetes master has initialized successfully!就表示初始化成功了。
要使用kubectl需要以下命令
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
查看初始化情况
kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 3d1h v1.13.2
kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-86c58d9df4-2nhd5 0/1 Pending 0 35m
kube-system coredns-86c58d9df4-l2wt9 0/1 Pending 0 35m
kube-system etcd-master 1/1 Running 0 34m
kube-system kube-apiserver-master 1/1 Running 0 34m
kube-system kube-controller-manager-master 1/1 Running 0 34m
kube-system kube-proxy-fqjvp 1/1 Running 0 35m
kube-system kube-scheduler-master 1/1 Running 0 34m
安装flannel网络
wget https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
安装node结点
在安装前,先完成前面的环境准备,docker安装和安装kubeadm等。
下载镜像源
vim pull-kube-image.sh
#!/bin/bash
images=(kube-proxy:v1.13.1
pause:3.1
coredns:1.2.6)
for imagename in ${images[@]}; do
docker pull mathlsj/$imagename
docker tag mathlsj/$imagename k8s.gcr.io/$imagename
docker rmi mathlsj/$imagename
done
docker pull quay.io/coreos/flannel:v0.10.0-amd64
查看镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.13.1 6fbfd87ede1f 7 days ago 80.2MB
k8s.gcr.io/pause 3.1 68112c580347 8 days ago 742kB
k8s.gcr.io/coredns 1.2.6 75ca836e805a 8 days ago 40MB
quay.io/coreos/flannel v0.10.0-amd64 f0fad859c909 11 months ago 44.6MB
查看token,在master结点上看
kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
km7adp.vu3fugeopqgyj8rk 23h 2019-01-15T09:22:48-05:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token
加入节点
kubeadm join --discovery-token km7adp.vu3fugeopqgyj8rk --discovery-token-ca-cert-hash sha256:4e05312726ad565688309951d6c8afb2965e1ce80f736d0123b4363581fcb106 192.168.239.200:6443
在master上查看状态
kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 92m v1.13.2
node1 Ready <none> 41m v1.13.2
kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system coredns-86c58d9df4-2nhd5 1/1 Running 0 84m 10.244.1.2 node1 <none> <none>
kube-system coredns-86c58d9df4-l2wt9 1/1 Running 0 84m 10.244.1.3 node1 <none> <none>
kube-system etcd-master 1/1 Running 0 83m 192.168.239.200 master <none> <none>
kube-system kube-apiserver-master 1/1 Running 0 83m 192.168.239.200 master <none> <none>
kube-system kube-controller-manager-master 1/1 Running 0 83m 192.168.239.200 master <none> <none>
kube-system kube-flannel-ds-amd64-786l8 1/1 Running 0 16m 192.168.239.200 master <none> <none>
kube-system kube-flannel-ds-amd64-pc4fp 1/1 Running 0 16m 192.168.239.201 node1 <none> <none>
kube-system kube-proxy-fqjvp 1/1 Running 0 84m 192.168.239.200 master <none> <none>
kube-system kube-proxy-skndl 1/1 Running 0 33m 192.168.239.201 node1 <none> <none>
kube-system kube-scheduler-master 1/1 Running 0 83m 192.168.239.200 master <none> <none>
参考文档