kebeadm 搭建k8s筆記

在全部節點上設置SELINUX爲permissive模式
# 修改配置
$ vi /etc/selinux/config
SELINUX=permissivenode

$ setenforce 0linux


全部節點設置/etc/hosts主機名,請根據實際狀況進行配置
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.161.150 k8s-master1
192.168.161.151 k8s-master2
192.168.161.152 k8s-master3
192.168.161.170 k8s-node1
192.168.161.171 k8s-node2
192.168.161.172 k8s-node3
192.168.161.160 k8s-vipgit


在全部節點上禁用swap
$ swapoff -agithub

# 禁用fstab中的swap項目
$ vi /etc/fstab
#/dev/mapper/centos-swap swap swap defaults 0 0docker

# 確認swap已經被禁用
$ cat /proc/swaps
Filename Type Size Used Prioritycentos

# 重啓主機
$ rebootapi

 

設置docker-ce的安裝yum源
# 安裝yum管理工具
$ yum install -y yum-utils網絡

# 添加阿里雲的yum源
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoapp

# 安裝docker-ce
$ yum install -y 3:docker-ce-18.09.3-3.el7.x86_64dom

# 啓動docker服務
$ systemctl enable docker && systemctl start docker

 

 

設置kubernetes安裝yum源
# 配置kubernetes軟件yum源
$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/apt/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/apt/doc/rpm-package-key.gpg
EOF


$ cat <<EOF > /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
repo_gpgcheck=0
EOF

 


安裝kubernetes
yum install -y kubeadm-1.14.1-0.x86_64 kubelet-1.14.1-0.x86_64 kubectl-1.14.1-0.x86_64


拉取鏡像
images=(
kube-apiserver:v1.14.1
kube-controller-manager:v1.14.1
kube-scheduler:v1.14.1
kube-proxy:v1.14.1
pause:3.1
etcd:3.3.10
coredns:1.3.1
)

for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
done


使用yum方式安裝flannel
yum install -y flannel

 

 

在全部節點上設置iptables參數
# 全部節點配置ip轉發
$ cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

# 讓配置生效
$ sysctl --system


echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables


初始化master節點
kubeadm init --kubernetes-version=v1.14.1 --pod-network-cidr=10.244.0.0/16


在這裏若是出現成功
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.161.150:6443 --token y4nlq5.enr99ie4axofcrs1 \
--discovery-token-ca-cert-hash sha256:887c079a03e3dcc311b4a9ec3fcac3c970ee2ab21067c2510704eda5dc0854c7


須要部署網絡插件,部署flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

 

查看結果: 這裏失敗了
kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-fb8b8dccf-p6m45 0/1 Pending 0 8m33s
coredns-fb8b8dccf-qknld 0/1 Pending 0 8m33s
etcd-k8s-master1 1/1 Running 0 7m30s
kube-apiserver-k8s-master1 1/1 Running 0 7m37s
kube-controller-manager-k8s-master1 1/1 Running 0 7m55s
kube-flannel-ds-amd64-842j7 0/1 Init:0/1 0 2m26s
kube-proxy-qjdt4 1/1 Running 0 8m33s
kube-scheduler-k8s-master1 1/1 Running 0 7m44s


解決辦法是 wget https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
cat 這個文件 而後看插件鏡像名稱:docker pull quay.io/coreos/flannel:v0.11.0-amd64
在全部節點上都須要這個,失敗的手動pull docker pull quay.io/coreos/flannel:v0.11.0-amd64

 


kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-fb8b8dccf-p6m45 0/1 ContainerCreating 0 17m
coredns-fb8b8dccf-qknld 0/1 ContainerCreating 0 17m
etcd-k8s-master1 1/1 Running 0 15m
kube-apiserver-k8s-master1 1/1 Running 0 16m
kube-controller-manager-k8s-master1 1/1 Running 0 16m
kube-flannel-ds-amd64-842j7 1/1 Running 0 10m
kube-proxy-qjdt4 1/1 Running 0 17m
kube-scheduler-k8s-master1 1/1 Running 0 16m

 

 

 

 

node加入master(這個根據初始化完成後的實際狀況來)
kubeadm join 192.168.161.150:6443 --token y4nlq5.enr99ie4axofcrs1 \
--discovery-token-ca-cert-hash sha256:887c079a03e3dcc311b4a9ec3fcac3c970ee2ab21067c2510704eda5dc0854c7

 

kubectl get pods -n kube-systemNAME READY STATUS RESTARTS AGEcoredns-fb8b8dccf-p6m45 1/1 Running 0 21mcoredns-fb8b8dccf-qknld 1/1 Running 0 21metcd-k8s-master1 1/1 Running 0 20mkube-apiserver-k8s-master1 1/1 Running 0 20mkube-controller-manager-k8s-master1 1/1 Running 0 20mkube-flannel-ds-amd64-842j7 1/1 Running 0 14mkube-flannel-ds-amd64-ltlvk 1/1 Running 0 94skube-flannel-ds-amd64-m69s6 1/1 Running 0 91skube-flannel-ds-amd64-tsq2j 1/1 Running 0 3m23skube-proxy-4jwgn 1/1 Running 0 91skube-proxy-8bqk9 1/1 Running 0 3m23skube-proxy-mmsb4 1/1 Running 0 94skube-proxy-qjdt4 1/1 Running 0 21mkube-scheduler-k8s-master1 1/1 Running 0 20m

相關文章
相關標籤/搜索