您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“如何使用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
環(huán)境:centos7
配置:2核4G起
注意事項:
docker版本最高支持18.06,高于要此版本報錯
kubernetes12.2+docker-ce18.06.1ce
(一)環(huán)境配置:
在master和node 端執(zhí)行:
1:安全策略規(guī)則配置
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:內(nèi)核設置:
關閉selinux
vim /etc/sysconfig/selinux
SELINUX=disable
修改內(nèi)核參數(shù)
$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
保存修改內(nèi)核參數(shù)
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
每個節(jié)點都修改下面值,
[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端分別執(zhí)行
[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版本已經(jīng)更新到18.9了,
所以不能指只有yum安裝最新版,要指定版本型號
$systemctl start docker
$systemctl enable docker
$systemctl status docker
執(zhí)行下面命令配置加速器:
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
base: mirrors.163.com
epel: mirrors.aliyun.com
extras: mirrors.aliyun.com
updates: mirrors.aliyun.com
kubernetes 272/272
源標識 源名稱 狀態(tài)
base/7/x86_64 CentOS-7 - Base 9,911
docker-ce-stable/x86_64 Docker CE Stable - x86_64 25
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,696
extras/7/x86_64 CentOS-7 - Extras 434
kubernetes Kubernetes Rope 272
updates/7/x86_64 CentOS-7 - Updates 1,614
repolist: 24,952
在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端執(zhí)行: ()注意修改為master地址)
kubeadm init \
--kubernetes-version=v1.12.2 \
--pod-network-cidr=10.244.0.0/16 \
--apiserver-advertise-address=192.168.1.220
master初始化之后會出現(xiàn)以下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控制集群需要,配置下環(huán)境變量
對于非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 用戶執(zhí)行以下配置環(huán)境變量
export KUBECONFIG=/etc/kubernetes/admin.conf
也可以直接放到~/.bash_profile
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
kubectl get pods --all-namespaces
node節(jié)點要安裝都軟件:
#yum install -y kubelet kubeadm kubectl
[root@k8n2 ~]# vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
node節(jié)點要安裝的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
執(zhí)行之前上面保留下來都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,查看節(jié)點可能啟動比較慢,要稍等,如果加不進去 要排查問題。。
(如果初始化集群出現(xiàn)問題,可以使用下面命令進行清理進行重新初始化:kubeadm reset)
“如何使用docker鏡像安裝Kubernetes1.12.2”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注億速云網(wǎng)站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。