Ubuntu 16.04搭建K8S集羣

Ubuntu 16.04搭建K8S集羣:node

vi /etc/apt/sources.list

deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stablelinux

deb http://mirrors.aliyun.com/ubuntu/ xenial mail restrictedgit

deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial maingithub

:wqdocker

apt-get update

apt-get install docker-ce

apt-get install kubeadm kubectl kubelet

初始化master節點:ubuntu

kubeadm config images list

vi images.sh (根據上步的image名修改腳本內容,去掉k8s.gcr.io/)

#!/bin/bashapi

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.3 k8s.gcr.io/kube-apiserver:v1.15.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.3 k8s.gcr.io/kube-controller-manager:v1.15.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.3 k8s.gcr.io/kube-scheduler:v1.15.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.3 k8s.gcr.io/kube-proxy:v1.15.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1bash

:wq網絡

sh images.sh

注:
執行這個腳本的緣由是國內沒法訪問k8s.gcr.io,因此經過下載阿里雲上的image再更名app

swapoff -a

kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.1.5

注:這步結束會給出slave加入集羣的命令

mkdir ~/.kube

cp -rv /etc/kubernetes/admin.conf ~/.kube/config

chown root:root ~/.kube/config

安裝網絡插件flannel(也能夠使用canal):

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

slave加入集羣:

swapoff -a

kubeadm join 10.0.1.5:6443 --token yio1o6.zq85eudygtevzvd1 --discovery-token-ca-cert-hash sha256:318eebe90133c8f9892ac00c072c584025f36f1b6dae3ae4b5948f8c981bd90f

驗證(在master上執行):

kubectl get nodes (狀態顯示爲Ready即正常,若是是NotReady,多是沒安裝網絡插件)

kubectl get pod -n kube-system -o wide (看到狀態爲Running即爲正常)

相關文章
相關標籤/搜索