如何使用docker镜像安装Kubernetes1.12.2

发布时间:2021-08-21 22:26:43 作者:chen
来源:亿速云 阅读:152

本篇内容介绍了“如何使用docker镜像安装Kubernetes1.12.2”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

kubernetes 1.12.2版本安装
起码准两台机器:master,node
ip: master:192.168.1.220
node1:192.168.1.221
node2:192.168.1.205
环境:centos7
配置:2核4G起
注意事项:
docker版本最高支持18.06,高于要此版本报错
kubernetes12.2+docker-ce18.06.1ce

(一)环境配置:
在master和node 端执行:

1:安全策略规则配置
systemctl  stop firewalld
systemctl disable firewalld
setenforce 0
iptables -F
iptables -t nat -F
iptables -I FORWARD -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT  
yum -y install ntp
ntpdate pool.ntp.org
systemctl start ntpd
systemctl enable ntpd

2:内核设置:

关闭selinux
vim /etc/sysconfig/selinux
SELINUX=disable

修改内核参数
$vim /etc/sysctl.conf
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
vm.swappiness=0

关闭swap
swapoff -a

注释自动挂载
vim /etc/fstab

关闭selinux
vim /etc/selinux/config
保存修改内核参数
sysctl -p

确保以下两个文件里面显示值为1:
[root@k8m1 ~]#  cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
1
[root@k8m1 ~]# cat /proc/sys/net/bridge/bridge-nf-call-ip6tables

每个节点都修改下面值,

[root@k8n2 ~]# vim /etc/sysconfig/kubelet

KUBELET_EXTRA_ARGS="fail-swap-on=false"

3:域名解析,免密登录,时间同步
a:
[root@k8m1 ~]# vim /etc/hosts
[root@k8m1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.220 k8m1
192.168.1.221 k8n1
192.168.1.205 k8n2

b:
[root@k8m1 ~]# vim /etc/hosts
[root@k8m1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ldQKudY4N7CV+VrQV6qCOeEC5KlKIeLk7F8tR/cm8kI root@k8m1
The key's randomart image is:
+---[RSA 2048]----+
|    .    ..=   ..|
|   o .  +.=.o .. |
|oo  +   .Oo+ ..  |
|B .. . .*== o.   |
| =.   .oS+.+.    |
|o.    oE..o.     |
|..   o.+ . o     |
|  . . o.o o      |
|   .    ..       |
+----[SHA256]-----+
[root@k8m1 ~]# ssh-copy-id -i ~/.ssh/id_rsa k8n1

[root@k8m1 ~]# ssh-copy-id -i ~/.ssh/id_rsa k8n2

c:master和node端分别执行

[root@k8m1 ~]# yum -y install ntp
[root@k8m1 ~]# ntpdate pool.ntp.org
10 Nov 11:07:32 ntpdate[50259]: step time server 193.228.143.22 offset 14.725020 sec
[root@k8m1 ~]# systemctl start ntpd
[root@k8m1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@k8m1 ~]#

(二)安装docker:安装官方要求安装
配置docker-CE源  :master node都要配置
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

$sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

$ yum list docker-ce --showduplicates | sort -r

$yum install docker-ce-18.06.1.ce
备注:目前kubernetes1.12.2支持docker版本最多18.06,docker版本已经更新到18.9了,
所以不能指只有yum安装最新版,要指定版本型号

$systemctl start docker
$systemctl enable docker
$systemctl status docker

执行下面命令配置加速器:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

然后重启docker
$systemctl restart docker

配置阿里云:
[root@k8n2 yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#yum repolist

(三)配置kubernetes源:

vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes Rope
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
enabled=1

[root@k8n2 yum.repos.d]# yum repolist
已加载插件:fastestmirror
kubernetes                                                                                        | 1.4 kB  00:00:00    
kubernetes/primary                                                                                |  37 kB  00:00:00    
Loading mirror speeds from cached hostfile

在master端安装:
#yum install -y kubelet kubeadm kubectl

kubeadm init --help   #查看初始化命令帮助

kubeadm config images list

使用下面这条命令:查看到所需要都安装组件有以下这些:
kubeadm config images list

服务组件:
k8s.gcr.io/kube-apiserver:v1.12.2
k8s.gcr.io/kube-controller-manager:v1.12.2
k8s.gcr.io/kube-scheduler:v1.12.2
k8s.gcr.io/kube-proxy:v1.12.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.2.24
k8s.gcr.io/coredns:1.2.2

这下做组件怎么安装能?当然是去dockerHub
使用下面命令docker pull下来:
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.12.2
docker pull mirrorgooglecontainers/pause-amd64:3.1
docker pull mirrorgooglecontainers/etcd-amd64:3.2.24
docker pull kuberneter/coredns:1.2.2

给下载下来都镜像组件tag上和服务组件同样都标签:
docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.12.2 k8s.gcr.io/kube-apiserver:v1.12.2
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.2 k8s.gcr.io/kube-controller-manager:v1.12.2
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.12.2 k8s.gcr.io/kube-scheduler:v1.12.2
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.12.2 k8s.gcr.io/kube-proxy:v1.12.2
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24
docker tag kuberneter/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2

初始化集群,只在master端执行: ()注意修改为master地址)
kubeadm init \
--kubernetes-version=v1.12.2 \
--pod-network-cidr=10.244.0.0/16 \
--apiserver-advertise-address=192.168.1.220

master初始化之后会出现以下token,要复制下来保存好,加node要用:
kubeadm join 192.168.1.220:6443 --token o4bmhn.12ppkvve2cecgk6m --discovery-token-ca-cert-hash sha256:03b9e1d1979288194bcf694c12a85217236319cfdf1b89aae803e430796c611b

如果上面都token忘记了 可以通过以下命令获得:
kubeadmin token list

此时root用户还不能使用kubelet控制集群需要,配置下环境变量
对于非root用户
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

启动faannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

root 用户执行以下配置环境变量

export KUBECONFIG=/etc/kubernetes/admin.conf
也可以直接放到~/.bash_profile

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile

kubectl get pods --all-namespaces

node节点要安装都软件:
#yum install -y kubelet kubeadm kubectl

[root@k8n2 ~]# vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"

node节点要安装的docker镜像:

docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.12.2
docker pull mirrorgooglecontainers/pause-amd64:3.1
docker pull kuberneter/coredns:1.2.2

docker pull mirrorgooglecontainers/etcd-amd64:3.2.24  #node媏的ETCD可以安装,
也可以不安装需要做ETCD 集群,安装就是

打标签
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.12.2 k8s.gcr.io/kube-proxy:v1.12.2
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
docker tag kuberneter/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2

执行之前上面保留下来都token:就会自己加入集群
kubeadm join 192.168.1.220:6443 --token o4bmhn.12ppkvve2cecgk6m --discovery-token-ca-cert-hash sha256:03b9e1d1979288194bcf694c12a85217236319cfdf1b89aae803e430796c611b

[root@k8m1 ~]# kubectl get nodes
NAME   STATUS   ROLES    AGE   VERSION
k8m1   Ready    master   22h   v1.12.2
k8n1   Ready    <none>   22h   v1.12.2
k8n2   Ready    <none>   37m   v1.12.2
[root@k8m1 ~]# kubectl get pods --all-namespaces  
NAMESPACE     NAME                           READY   STATUS    RESTARTS   AGE
kube-system   coredns-576cbf47c7-jqcn8       1/1     Running   0          22h
kube-system   coredns-576cbf47c7-rqqvk       1/1     Running   0          22h
kube-system   etcd-k8m1                      1/1     Running   0          22h
kube-system   kube-apiserver-k8m1            1/1     Running   0          22h
kube-system   kube-controller-manager-k8m1   1/1     Running   0          22h
kube-system   kube-flannel-ds-amd64-ck799    1/1     Running   1          22h
kube-system   kube-flannel-ds-amd64-nkdzg    1/1     Running   0          38m
kube-system   kube-flannel-ds-amd64-tjp27    1/1     Running   0          22h
kube-system   kube-proxy-8b7ds               1/1     Running   0          38m
kube-system   kube-proxy-dmswb               1/1     Running   0          22h
kube-system   kube-proxy-pm7wt               1/1     Running   0          22h
kube-system   kube-scheduler-k8m1            1/1     Running   0          22h

OK,查看节点可能启动比较慢,要稍等,如果加不进去 要排查问题。。

(如果初始化集群出现问题,可以使用下面命令进行清理进行重新初始化:kubeadm reset)

“如何使用docker镜像安装Kubernetes1.12.2”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. docker镜像的使用
  2. Docker下怎么使用zookeeper镜像

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

kubernetes docker

上一篇:php数组的概述及分类

下一篇:云服务器有哪些优点

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》