root@cka-1:~# vim /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda2 during curtin installation /dev/disk/by-uuid/aabac2dc-9464-4ed0-ae98-37700ee61cf8 / ext4 defaults 0 0 #/swap.img none swap sw 0 0 👈 注释swap一行
查看swap设备的信息 root@cka-1:~# swapon -s Filename Type Size Used Priority /swap.img file 4001788 0 -2
student@cka-1:~$ sudo cat /usr/lib/systemd/system/docker.service ... [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd 👈 ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always
在所有节点上添加阿里kuberneter源 student@cka-1:~$ sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF > deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main > EOF
查看生成的drop-in文件 student@cka-1:~$ sudo cat /etc/apt/sources.list.d/kubernetes.list deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main '意思是下载kubernetes时在阿里的镜像站' > node1 和 node2 同理
更新本地缓存(同步阿里的kubernetes仓库) student@cka-1:~$ sudo apt update ... 79 packages can be upgraded. Run 'apt list --upgradable' to see them. > node1 和 node2 同理
###如果出现以下报错,删除/var/lib/dpkg/lock-frontend.文件也不行的话,只能重启解决### Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 38Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process
固定kubeadm、kubelet、kubectl的版本 student@cka-1:~$ sudo apt-mark hold kubeadm kubelet kubectl kubeadm set on hold. kubelet set on hold. kubectl set on hold. > node1 和 node2 同理
查看节点 student@cka-1:~$ kubectl get nodes NAME STATUS ROLES AGE VERSION cka-1.example.com NotReady control-plane,master 40m v1.23.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
###如果初始化master报错,是因为没有添加服务管理选项### ... [etcd] Creating static Pod manifest forlocal etcd in"/etc/kubernetes/manifests" [wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s [kubelet-check] Initial timeout of 40s passed. [kubelet-check] It seems like the kubelet isn't running or healthy. [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused. 解决 👇 root@cka-1:~# kubeadm reset root@cka-1:~# reboot 添加服务管理选项 root@cka-1:~# sed -i "s#^ExecStart=/usr/bin/dockerd.*#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd#g" /usr/lib/systemd/system/docker.service 再进行初始化 student@cka-1:~$ sudo kubeadm init ...
此时utility还不能管理k8s集群,因为默认是连接到了本地的8080端口 [root@utility ~]# kubectl get nodes The connection to the server localhost:8080 was refused - did you specify the right host or port?
###开机生效### student@cka-1:~$ vim ~/.bashrc student@cka-1:~$ tail ~/.bashrc # sources /etc/bash.bashrc). if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi