kubeadm 安装k8s集群 master/node机器的基础设置
安装k8s集群 master/node机器的基础设置
systemctl disable firewalld
systemctl stop firewalld
vi /etc/selinux/config
SELINUX=disabled
关闭 swap
swapoff -a
vi /etc/fstab
#/dev/mapper/centos-swap swap swap defaults 0 0
hostnamectl set-hostname k8smaster
hostnamectl --pretty
hostnamectl --static
hostnamectl --transient
vi /etc/sysctl.conf
fs.file-max = 65535
vm.swappiness = 0
vi /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
cd /etc/systemd/system/kubelet.service.d
vi 10-kubeadm.conf
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"
cd /etc/yum.repos.d/
配置各节点阿里K8S 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=0
EOF
yum -y install epel-release
yum clean all
yum makecache
//双机秘钥认证访问
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.3.14
配置一个阿里云的加速器:
登录 https://cr.console.aliyun.com/
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://0zsv5jey.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
下载K8S相关镜像
OK,解决完加速器的问题之后,开始下载k8s相关镜像,下载后将镜像名改为k8s.gcr.io/开头的名字,以便kubeadm识别使用。
#!/bin/bash
images=(kube-proxy-amd64:v1.10.0 kube-scheduler-amd64:v1.10.0 kube-controller-manager-amd64:v1.10.0 kube-apiserver-amd64:v1.10.0
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
上面的shell脚本主要做了3件事,下载各种需要用到的容器镜像、重新打标记为符合k8s命令规范的版本名称、清除旧的容器镜像。
提示:镜像版本一定要和kubeadm安装的版本一致,否则会出现time out问题。
安装特定的docker 版本:
yum remove docker-ce docker-ce-cli containerd.io docker-selinux
cd /var/lib
rm -rf docker
rm -rf docker-engine
wget 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
rpm -ivh docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
yum list docker-ce --showduplicates | sort -r
yum list containerd.io --showduplicates | sort -r
yum list kubelet --showduplicates | sort -r
yum install docker-ce-17.03.2.ce-1.el7.centos docker-ce-cli-17.03.2.ce-1.el7.centos containerd.io-1.2.0-3.el7
yum list container-selinux --showduplicates |sort -r
kubeadm init --kubernetes-version=v1.10.0 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubeadm join 192.168.3.131:6443 --token bx964l.f25qaz7hjoq9eoor --discovery-token-ca-cert-hash sha256:e3aefbbdd3252983e0081e55b5e6a00131d8edfc19840942833b3d669d417550
flannel插件:
Master Node01节点 同样安装步骤
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
kubernetes-dashboard 可视化插件:
wget
http://mirror.faasx.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
vi kubernetes-dashboard.yaml
# ------------------- Dashboard Service ------------------- #
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
ports:
- port: 443
targetPort: 8443
type: NodePort
selector:
k8s-app: kubernetes-dashboard
或者:
kubectl -n kube-system edit service kubernetes-dashboard
kubectl apply -f kubernetes-dashboard.yaml
vi admin-user.yaml
# admin-user.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
vi admin-user-role-binding.yaml
# admin-user-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
kubectl create -f admin-user.yaml
kubelctl create -f admin-user-role-binding.yaml
获取token:
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
得到 映射的端口:
kubectl -n kube-system get service kubernetes-dashboard
https://192.168.3.131:32025
token 登陆