使用kubeadm安裝kubernetes

衡子發表於2018-05-21

安裝kubenetes的方法有多種,本文將介紹如何用kubeadm安裝kubernetes。

一 node準備

1 /etc/hosts檔案

192.168.235.133 kube01
192.168.235.134 kube02
192.168.235.135 kube03

2 關閉swap

 

swapoff -a 

註釋/etc/fstab中的swap掛載

#/dev/mapper/centos-swap swap swap defaults 0 0

 3 修改核心引數

cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

4 安裝docker

yum install docker -y
systemctl enable docker
systemctl start docker

二 安裝kubeadm

1 增加yum的repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

2 安裝

setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet

三 用kubeadm安裝kubenetes叢集

1 用kubeadm初始化

在master節點執行:

kubeadm init \
> --pod-network-cidr=10.244.0.0/16 \
> --apiserver-advertise-address=192.168.235.133

安裝完成:

Your Kubernetes master 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/

You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.235.133:6443 --token 8ojndu.qaow6tuo95psar5g --discovery-token-ca-cert-hash sha256:79c955c758bd76f02335c33540f3880039bcf9aa137c9b67366a990ccefbaead

2 安裝Pod netwok

 

mkdir -p ~/k8s/
cd ~/k8s
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f  kube-flannel.yml

 3 將node2和node3加入到叢集中

kubeadm join 192.168.235.133:6443 --token 8ojndu.qaow6tuo95psar5g --discovery-token-ca-cert-hash sha256:79c955c758bd76f02335c33540f3880039bcf9aa137c9b67366a990ccefbaead

 在master節點上觀察:

[root@kube01 k8s]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
kube01 Ready master 23m v1.10.2
kube02 Ready <none> 5m v1.10.2
kube03 Ready <none> 5m v1.10.2

總結:

使用kubeadm可以方便的安裝kubernetes叢集。

相關文章