1. 程式人生 > >kubeadm,minikube安裝kubernetes

kubeadm,minikube安裝kubernetes

kubernetes快速安裝方式一般為二種:kubeadm,minikube

minikube安裝方式:https://github.com/kubernetes/minikube,有詳細的使用方式請自行檢視(適合單機部署開發)

systemctl stop firewalld && systemctl disable firewalld

swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab

setenforce  0 
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux 
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config 
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux 
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config

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

sysctl -p /etc/sysctl.d/k8s.conf && ls /proc/sys/net/bridge

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/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF


yum install -y epel-release yum-utils device-mapper-persistent-data lvm2 net-tools conntrack-tools wget vim  ntpdate libseccomp libtool-ltdl etcd 


安裝docker(kubeadm目前支援docker最高版本是17.03.x)
yum install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm  -y
yum install https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm  -y

修改配置檔案 vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd   -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock  --registry-mirror=https://ms3cfraz.mirror.aliyuncs.com(阿里加速,請自行設定)

systemctl daemon-reload && systemctl restart docker && systemctl enable docker && systemctl status docker

yum install -y kubelet kubeadm kubectl && systemctl enable kubelet

#vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#修改這一行
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
#新增這一行
Environment="KUBELET_EXTRA_ARGS=--v=2 --fail-swap-on=false --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0"

systemctl daemon-reload && systemctl enable kubelet
systemctl status kubelet


提示:映象版本一定要和kubeadm安裝的版本一致,否則會出現time out問題
shell指令碼主要做了3件事,下載各種需要用到的容器映象、重新打標記為符合k8s命令規範的版本名稱、清除舊的容器映象
#!/bin/bash
images=(kube-proxy-amd64:v1.10.2 kube-scheduler-amd64:v1.10.2 kube-controller-manager-amd64:v1.10.2 kube-apiserver-amd64:v1.10.2
etcd-amd64:3.1.12 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.8 k8s-dns-kube-dns-amd64:1.14.8
k8s-dns-dnsmasq-nanny-amd64:1.14.8)
for imageName in ${images[@]} ; do
  docker pull keveon/$imageName
  docker tag keveon/$imageName k8s.gcr.io/$imageName
  docker rmi keveon/$imageName
done

kubeadm init --kubernetes-version=v1.10.2 --pod-network-cidr=10.244.0.0/16

初始化失敗後處理辦法 kubeadm reset

export KUBECONFIG=/etc/kubernetes/admin.conf

mkdir -p /etc/cni/net.d/
cat <<EOF> /etc/cni/net.d/10-flannel.conf
{
“name”: “cbr0”,
“type”: “flannel”,
“delegate”: {
“isDefaultGateway”: true
}
}
EOF
mkdir /usr/share/oci-umount/oci-umount.d -p
mkdir /run/flannel/
cat <<EOF> /run/flannel/subnet.env
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.1.0/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
EOF
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

node節點新增:

kubeadm join 192.168.117.142:6443 --token p96xui.2p42stlp5c6frdql --discovery-token-ca-cert-hash sha256:1bf5643bc9b75c5f98e9fb6229dfaa8c35e6a446d45788f3f5efa7fcf8cf1e9c