kubernetes kubeadm安装v1.14

时间:2022-08-09 01:37:46

1.我们这里准备两台Centos7的主机用于安装,后续节点可以根究需要添加即可:
master node01两台都得改:
cat /etc/hosts
192.168.71.134 master
192.168.71.135 node1

$ systemctl stop firewalld
$ systemctl disable firewalld

$ setenforce 0
$ cat /etc/selinux/config
SELINUX=disabled

创建/etc/sysctl.d/k8s.conf文件,添加如下内容:

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1

sysctl -p /etc/sysctl.d/k8s.conf

2.之后导入1.14.1最新包和test.sh脚本
包在百度网盘里面
yum -y install bzip2
tar xf kubernetes-images.bzip2
chmod +x test.sh

3.安装 kubeadm、kubelet、kubectl

$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

$ yum makecache fast && yum install -y kubelet-1.14.1-0 kubeadm-1.14.1-0 kubectl-1.14.1-0

vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
添加两个环境变量:
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --fail-swap-on=false"
$ systemctl daemon-reload

关闭swap分区
swapoff -a
4.集群安装初始化

$ kubeadm init --kubernetes-version=v1.14.1 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.71.134

成功才能执行下一步:

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

5.安装 Pod Network
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f  kube-flannel.yml

1.node1节点
2.之后导入1.14.1最新包和test.sh脚本
包在百度网盘里面
yum -y install bzip2
tar xf kubernetes-images.bzip2
chmod +x test.sh

3.安装kubelet、kubeadm、kubectl

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

4.$ yum makecache fast && yum install -y kubelet-1.14.1-0 kubeadm-1.14.1-0 kubectl-1.14.1-0
出错清理kubeadm: kubeadm reset

kubeadm join 192.168.71.134:6443 --token doochb.x6yskgs920ylekj0 \
    --discovery-token-ca-cert-hash sha256:aea8399ac97da6bb31895be38fe5f1c3182188259be2251434fb8ff46e49d202
    
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

提示成功!

scp -r /root/.kube/config root@192.168.71.135:/root/.kube
kubectl get nodes
kubectl get cs
kubectl get pods --all-namespaces -o wide

在master执行:
kubectl get svc -n kube-system
kubectl describe svc kubernetes-dashboard -n kube-system

kubectl describe serviceaccount admin -n kube-system
kubectl get secret -n kube-system
kubectl describe secret admin-token-xp5gx -n kube-system
API文档:
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/