k8s安装部署与卸载

查看k8s的面板token

kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')

1、docker安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
启动docker并设置开机自启动
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"]
}

2、关闭交换分区

一、临时关闭
swapoff -a
二、永久关闭

注释掉/etc/fstab的配置文件中的swap那行
命令方式关闭

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

3、禁用selinux

一、临时关闭
setenforce 0
二、永久关闭

修改配置文件/etc/selinux/config中enforcing改成disabled,或者使用下面命令行修改

sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

4、关闭防火墙

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

5、配置k8s的yum源

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
1、安装kubectl、kubelet、kubeadm,设置kubelet开机启动,启动kubelet。
yum install -y kubectl-1.20.5 kubelet-1.20.5 kubeadm-1.20.5
systemctl enable kubelet
systemctl start kubelet
2、初始化kubernetes集群(里面的版本必须对应安装的软件包版本)
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

6、安装calico网络

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
报错的话用下面的
[root@k8s-master ~]$ curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O

7、安装k8s的控制面板

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。

卸载docker
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-
k8s安装部署与卸载_第1张图片

你可能感兴趣的:(linux,docker,linux,运维)