利用rpm快速部署k8s
#!/bin/bash #快速安装k8s #by love19791126 107420988@qq.com
pwd=$(pwd)
masteripaddr=#(ip a show dev ens33|grep -w inet|awk '{print $2}'|sed 's/\/.*//')
#定义版本
K8S_VERSION=v1.13.8 ETCD_VERSION=3.2.24 DASHBOARD=v1.10.1 FLANNEL_VERSION=v0.11.0-amd64 DNS_VERSION=1.2.6 PAUSE_VERSION=3.1
#yum源
cp docker-ce.repo /etc/yum.repos.d/docker-ce.repo
cp kubernetes.repo /etc/yum.repos.d/kubernetes.repo yum clean all yum makecache
#安装docker-ce 此步骤要是master和node都执行 yum -y install yum-utils lvm2 device-mapper-persistent-data docker-ce
#启动docker
systemctl enable docker
systemctl start docker
systemctl status docker
#daemon cp daemon.json /etc/docker/daemon.json
#重新启动
systemctl restart docker
systemctl status docker
# 基本组件
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:$ETCD_VERSION docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:$PAUSE_VERSION docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:$DASHBOARD
# #网络组件 docker pull quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64
# #修改tag
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION k8s.gcr.io/kube-apiserver:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION k8s.gcr.io/kube-controller-manager:$K8S_VERSION docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION k8s.gcr.io/kube-scheduler:$K8S_VERSION docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION k8s.gcr.io/kube-proxy:$K8S_VERSION docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:$ETCD_VERSION k8s.gcr.io/etcd:$ETCD_VERSION docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:$PAUSE_VERSION k8s.gcr.io/pause:$PAUSE_VERSION docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION k8s.gcr.io/coredns:$DNS_VERSION docker tag quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64 quay.io/coreos/flannel:v0.11.0-amd64 docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:$dashboard k8s.gcr.io/kubernetes-dashboard-amd64:$dashboard
#安装kubeadm kubectl kubelet
yum install kubelet kubeadm kubectl --disableexcludes=kubernetes
#启动kubelet
systemctl enable kubelet
systemctl start kubelet
systemctl status kubelet
#初始化master 此步骤要是master执行
kubeadm init --kubernetes-version=$K8S_VERSION --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=$masteripaddr
#配置kube
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config
#查看节点状态 kubectl get nodes
#node kubeadm join $masteripaddr:6443 --token $token --discovery-token-ca-cert-hash $sha256
#安装网络插件 kubectl apply -f kube-flannel.yml
#查看网络插件 kubectl get pods --namespace kube-system
#安装dashboard
kubectl apply -f kubernetes-dashboard.yaml
kubectl get pods --namespace kube-system kubectl get svc --namespace kube-system
#获取token kubectl -n 命名空间名称(默认是kubs-system) describe secret $(kubectl -n kube-system get secret | grep 指定用户的名字(admin) | awk '{print $1}')
最后IP加端口登录dashboard,利用token登录