#关闭swap
swapoff -a
rm -f /swap.img
vim /etc/fstab
# /swap.img
#开启ip转发
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
#查看状态
sysctl -p
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
apt install -y docker-ce
apt install -y docker-compose
systemctl enable docker
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-cache madison kubelet
apt-get install -y kubelet=1.18.4-00 kubeadm=1.18.4-00 kubectl=1.18.4-00
sudo systemctl enable kubelet && sudo systemctl start kubelet
kubeadm config images list --kubernetes-version=v1.18.4
k8s.gcr.io/kube-apiserver:v1.18.4
k8s.gcr.io/kube-controller-manager:v1.18.4
k8s.gcr.io/kube-scheduler:v1.18.4
k8s.gcr.io/kube-proxy:v1.18.4
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.7
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.18.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.18.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.18.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.18.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.18.4 k8s.gcr.io/kube-apiserver:v1.18.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.18.4 k8s.gcr.io/kube-controller-manager:v1.18.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.18.4 k8s.gcr.io/kube-scheduler:v1.18.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.18.4 k8s.gcr.io/kube-proxy:v1.18.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.7 k8s.gcr.io/coredns:1.6.7
kubeadm init --kubernetes-version=v1.18.4 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
初始化完成之后会出现提示,Your Kubernetes control-plane has initialized successfully!,之后将后面的内容保存到一个文件中,先不添加节点检查集群状态是否正常。
kubectl get componentstatus
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get pods -n kube-system -l app=flannel
检查节点是否准备完成
kubectl get nodes
为node的角色打标签
kubectl label node node01 node-role.kubernetes.io/node=node
部署Prometheus+Grafana
#获取相关文件
git clone https://gitee.com/liugpwwwroot/k8s-prometheus-grafana.git
#部署Node-exporter组件
kubectl create -f k8s-prometheus-grafana/node-exporter.yaml
#部署prometheus组件
kubectl create -f k8s-prometheus-grafana/prometheus/rbac-setup.yaml
kubectl create -f k8s-prometheus-grafana/prometheus/configmap.yaml
kubectl create -f k8s-prometheus-grafana/prometheus/prometheus.deploy.yml
kubectl create -f k8s-prometheus-grafana/prometheus/prometheus.svc.yml
#部署grafana组件
kubectl create -f k8s-prometheus-grafana/grafana/grafana-deploy.yaml
kubectl create -f k8s-prometheus-grafana/grafana/grafana-svc.yaml
kubectl create -f k8s-prometheus-grafana/grafana/grafana-ing.yaml
#查看相应服务
kubectl get svc -n kube-system
之后暴露端口进行访问即可
如果单机master跑prometheus和grafana的话可能会因为调度问题导致处于pending状态,这时候需要修改允许master部署pod
kubectl taint nodes --all node-role.kubernetes.io/master-