kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
systemctl enable docker && systemctl start docker
systemctl daemon-reload
systemctl restart docker
systemctl status docker
sudo vi /etc/docker/daemon.json
{
"registry-mirrors" : ["https://mj9kvemk.mirror.aliyuncs.com"]
}
swapoff -a
注释掉/etc/fstab的配置文件中的swap那行
命令方式关闭
sed -i 's/.*swap.*/#&/' /etc/fstab
setenforce 0
修改配置文件/etc/selinux/config中enforcing改成disabled,或者使用下面命令行修改
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
systemctl stop firewalld.service
systemctl disable firewalld.service
需要修改驱动,默认是cgroup,需要改成systemd
docker info | grep Cgroup
vim /usr/lib/systemd/system/docker.service
# 在ExecStart命令中添加
--exec-opt native.cgroupdriver=systemd
重启服务
systemctl daemon-reload
systemctl restart docker
docker info | grep Cgroup
vim /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
yum install -y kubectl-1.20.5 kubelet-1.20.5 kubeadm-1.20.5
systemctl enable kubelet
systemctl start kubelet
kubeadm init --apiserver-advertise-address=0.0.0.0 \
--apiserver-cert-extra-sans=127.0.0.1 \
--image-repository=registry.aliyuncs.com/google_containers \
--ignore-preflight-errors=all \
--kubernetes-version=v1.20.5 \
--service-cidr=10.10.0.0/16 \
--pod-network-cidr=10.18.0.0/16 \
--v=5 //不添加这个可能存在版本要求大于等于5的报错
kubeadm config images list
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get node
kubectl get pod --all-namespaces
此时查看node节点为NotReady状态,因为coredns pod没有启动,缺少网络pod
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
报错的话用下面的
[root@k8s-master ~]$ curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended.yaml
修改这个配置文件
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort #添加这行
ports:
- port: 443
targetPort: 8443
nodePort: 30000 #添加这行
selector:
k8s-app: kubernetes-dashboard
kubectl create -f recommended.yaml
kubectl get svc -n kubernetes-dashboard
kubectl create sa dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl -n kube-system describe $(kubectl -n kube-system get secret -n kube-system -o name | grep namespace) | grep token
kubectl taint nodes --all node-role.kubernetes.io/master-
到此k8s安装完成,下面就是卸载k8s。
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
卸载podman
yum erase podman buildah
卸载k8s
yum remove -y kubelet kubeadm kubectl
kubeadm reset -f
modprobe -r ipip
lsmod
rm -rf ~/.kube/
rm -rf /etc/kubernetes/
rm -rf /etc/systemd/system/kubelet.service.d
rm -rf /etc/systemd/system/kubelet.service
rm -rf /usr/bin/kube*
rm -rf /etc/cni
rm -rf /opt/cni
rm -rf /var/lib/etcd
rm -rf /var/etcd
当磁盘占用超过85%之后,k8s面板的状态都会异常,
会存在脏节点。
禁用master部署pod
kubectl taint nodes k8s-master(节点名称) node-role.kubernetes.io/master=true:NoSchedule
查看污点:
kubectl describe nodes 节点名称
删除污点(根据上述的常看,或者禁止来删除)
kubectl taint nodes 节点名称 node-role.kubernetes.io/master-