美文网首页
离线重复安装k3s的tips

离线重复安装k3s的tips

作者: 万州客 | 来源:发表于2023-09-30 08:40 被阅读0次

    网上成熟的k3s离线安装k3s文档一抓一大把,那如果要重复安装,就要有小的tips了

    我之前安装过很多次k3s或是k3d,那如果要重复安装,要注意哪些细节呢?

    一,全新离线安装k3s

    全新安装k3s很简单,
    以下这个指南就可以。
    https://zhuanlan.zhihu.com/p/627350047
    正常输出如下:

    [root@127 k3s]# cp ./k3s /usr/local/bin/
    [root@127 k3s]# INSTALL_K3S_SKIP_DOWNLOAD=true ./k3s-install.sh
    [INFO]  Skipping k3s download and verify
    [INFO]  Skipping installation of SELinux RPM
    [INFO]  Creating /usr/local/bin/kubectl symlink to k3s
    [INFO]  Creating /usr/local/bin/crictl symlink to k3s
    [INFO]  Creating /usr/local/bin/ctr symlink to k3s
    [INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
    [INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
    [INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
    [INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
    [INFO]  systemd: Enabling k3s unit
    Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
    [INFO]  systemd: Starting k3s
    

    二,删除k3s

    要删除k3s,以下命令就可以。

    [root@127 k3s]# k3s-uninstall.sh 
    ++ id -u
    + '[' 0 -eq 0 ']'
    + /usr/local/bin/k3s-killall.sh
    + for service in '/etc/systemd/system/k3s*.service'
    + '[' -s /etc/systemd/system/k3s.service ']'
    ++ basename /etc/systemd/system/k3s.service
    + systemctl stop k3s.service
    + for service in '/etc/init.d/k3s*'
    + '[' -x '/etc/init.d/k3s*' ']'
    + killtree 2815 2989 3038 3043 3066
    + kill -9 2815 2953 2989 3073 3038 3133 3043 3103 3066 3134
    + do_unmount_and_remove /run/k3s
    + set +x
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/b899f135d3da2a21f4b79448d75feb027e848449c318d426c40b895db1f4db7a/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/7b781b3465814f0b3fc0c91f1cf0b7be1e8ae3cec9d6b76b3fa984d01d8de6b1/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/69051633aab003fc045b32db7df2a29a7f3be91b38d7adc4cc0b056b1a7f04e7/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/4a4b44ddffaddc39bb1619357c821404ce69859e6987763a97bb680dde39aedb/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/3b6fcd0837463c2b88e01215ccbd3ad029bce66c7c27a097e8fe919117cc6275/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/b899f135d3da2a21f4b79448d75feb027e848449c318d426c40b895db1f4db7a/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/7b781b3465814f0b3fc0c91f1cf0b7be1e8ae3cec9d6b76b3fa984d01d8de6b1/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/69051633aab003fc045b32db7df2a29a7f3be91b38d7adc4cc0b056b1a7f04e7/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/4a4b44ddffaddc39bb1619357c821404ce69859e6987763a97bb680dde39aedb/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/3b6fcd0837463c2b88e01215ccbd3ad029bce66c7c27a097e8fe919117cc6275/shm 
    + do_unmount_and_remove /var/lib/rancher/k3s
    + set +x
    + do_unmount_and_remove /var/lib/kubelet/pods
    + set +x
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/d826c9bb-294b-4451-ae11-8cc80408f9b6/volumes/kubernetes.io~projected/kube-api-access-2sg2w 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/c19ed451-bff6-40c2-ab9e-0a2c40ad05f3/volumes/kubernetes.io~projected/kube-api-access-gnpqd 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/a2dfb28e-a6dd-488d-8153-1ee082d18aef/volumes/kubernetes.io~secret/values 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/a2dfb28e-a6dd-488d-8153-1ee082d18aef/volumes/kubernetes.io~projected/kube-api-access-wlbcs 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/9cc9a544-3e2c-401f-8bdb-27f41f412a8c/volumes/kubernetes.io~projected/kube-api-access-rjcjv 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/37e80d59-39f5-4a80-b862-618981a0e7ad/volumes/kubernetes.io~secret/values 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/37e80d59-39f5-4a80-b862-618981a0e7ad/volumes/kubernetes.io~projected/kube-api-access-rvhtw 
    + do_unmount_and_remove /var/lib/kubelet/plugins
    + set +x
    + do_unmount_and_remove /run/netns/cni-
    + set +x
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-e8c90798-3cee-2bc8-6fcd-1b4039ec754d 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-c9ffe531-6b04-a135-2785-1053041d1240 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-72a43732-bf8d-40d8-9195-a0ec153ac526 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-4e115461-0d3e-9704-833b-a6ea1e7b2b8b 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-27138efb-7c36-e664-fa50-433c5116025b 
    + ip netns show
    + grep cni-
    + xargs -r -t -n 1 ip netns delete
    + remove_interfaces
    + ip link show
    + grep 'master cni0'
    + read ignore iface ignore
    + iface=vethb6cb3710
    + '[' -z vethb6cb3710 ']'
    + ip link delete vethb6cb3710
    + read ignore iface ignore
    + iface=veth1e70044b
    + '[' -z veth1e70044b ']'
    + ip link delete veth1e70044b
    + read ignore iface ignore
    + iface=vetha3301075
    + '[' -z vetha3301075 ']'
    + ip link delete vetha3301075
    Cannot find device "vetha3301075"
    + read ignore iface ignore
    + iface=vethca30caad
    + '[' -z vethca30caad ']'
    + ip link delete vethca30caad
    Cannot find device "vethca30caad"
    + read ignore iface ignore
    + ip link delete cni0
    + ip link delete flannel.1
    + ip link delete flannel-v6.1
    Cannot find device "flannel-v6.1"
    + ip link delete kube-ipvs0
    Cannot find device "kube-ipvs0"
    + ip link delete flannel-wg
    Cannot find device "flannel-wg"
    + ip link delete flannel-wg-v6
    Cannot find device "flannel-wg-v6"
    ++ command -v tailscale
    + '[' -n '' ']'
    + rm -rf /var/lib/cni/
    + iptables-save
    + grep -v KUBE-
    + grep -v CNI-
    + iptables-restore
    + grep -iv flannel
    + ip6tables-save
    + grep -v KUBE-
    + grep -v CNI-
    + grep -iv flannel
    + ip6tables-restore
    + command -v systemctl
    /usr/bin/systemctl
    + systemctl disable k3s
    Removed symlink /etc/systemd/system/multi-user.target.wants/k3s.service.
    + systemctl reset-failed k3s
    Failed to reset failed state of unit k3s.service: Unit k3s.service is not loaded.
    + systemctl daemon-reload
    + command -v rc-update
    + rm -f /etc/systemd/system/k3s.service
    + rm -f /etc/systemd/system/k3s.service.env
    + trap remove_uninstall EXIT
    + for cmd in kubectl crictl ctr
    + '[' -L /usr/local/bin/kubectl ']'
    + for cmd in kubectl crictl ctr
    + '[' -L /usr/local/bin/crictl ']'
    + rm -f /usr/local/bin/crictl
    + for cmd in kubectl crictl ctr
    + '[' -L /usr/local/bin/ctr ']'
    + rm -rf /etc/rancher/k3s
    + rm -rf /run/k3s
    + rm -rf /run/flannel
    + rm -rf /var/lib/rancher/k3s
    + rm -rf /var/lib/kubelet
    + rm -f /usr/local/bin/k3s
    + rm -f /usr/local/bin/k3s-killall.sh
    + type yum
    + yum remove -y k3s-selinux
    Loaded plugins: fastestmirror
    No Match for argument: k3s-selinux
    No Packages marked for removal
    + rm -f '/etc/yum.repos.d/rancher-k3s-common*.repo'
    + remove_uninstall
    + rm -f /usr/local/bin/k3s-uninstall.sh
    [root@127 k3s]# k3s-uninstall.sh 
    -bash: /usr/local/bin/k3s-uninstall.sh: No such file or directory
    [root@127 k3s]# k3s-uninstall.sh 
    -bash: /usr/local/bin/k3s-uninstall.sh: No such file or directory
    [root@127 k3s]# INSTALL_K3S_SKIP_DOWNLOAD=true ./k3s-install.sh
    [INFO]  Skipping k3s download and verify
    [ERROR]  Executable k3s binary not found at /usr/local/bin/k3s
    [root@127 k3s]# cp ./k3s /usr/local/bin/
    [root@127 k3s]# INSTALL_K3S_SKIP_DOWNLOAD=true ./k3s-install.sh
    [INFO]  Skipping k3s download and verify
    [INFO]  Skipping installation of SELinux RPM
    [INFO]  Skipping /usr/local/bin/kubectl symlink to k3s, already exists
    [INFO]  Creating /usr/local/bin/crictl symlink to k3s
    [INFO]  Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
    [INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
    [INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
    [INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
    [INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
    [INFO]  systemd: Enabling k3s unit
    Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
    [INFO]  systemd: Starting k3s
    [root@127 k3s]# k3s-uninstall.sh 
    ++ id -u
    + '[' 0 -eq 0 ']'
    + /usr/local/bin/k3s-killall.sh
    + for service in '/etc/systemd/system/k3s*.service'
    + '[' -s /etc/systemd/system/k3s.service ']'
    ++ basename /etc/systemd/system/k3s.service
    + systemctl stop k3s.service
    + for service in '/etc/init.d/k3s*'
    + '[' -x '/etc/init.d/k3s*' ']'
    + killtree 4381 4523 4564 4568 4569
    + kill -9 4381 4503 4523 4596 4564 4632 4568 4627 4569 4666
    + do_unmount_and_remove /run/k3s
    + set +x
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/ecce8fd2a6e91f2d2122c007e42cd957bde0598f1b33351d386c74037c5738c5/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/cd832455533d7d713f94751977073fecc253770e1eab1ce5f354b3fbaf32563d/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/92db4feb1625dd066b00c4c3cacb018667437d88cc8257235c100fcd8e2cb836/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/596afe20f8c5b22337ea18dcd97b9ab682ea6ce8223b0f81c289611598c4511b/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.runtime.v2.task/k8s.io/1eb77540a38dbd5f10c3dde597a9fd4d60780131ca68fe07e650b676863a934d/rootfs 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/ecce8fd2a6e91f2d2122c007e42cd957bde0598f1b33351d386c74037c5738c5/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/cd832455533d7d713f94751977073fecc253770e1eab1ce5f354b3fbaf32563d/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/92db4feb1625dd066b00c4c3cacb018667437d88cc8257235c100fcd8e2cb836/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/596afe20f8c5b22337ea18dcd97b9ab682ea6ce8223b0f81c289611598c4511b/shm 
    sh -c umount "$0" && rm -rf "$0" /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/1eb77540a38dbd5f10c3dde597a9fd4d60780131ca68fe07e650b676863a934d/shm 
    + do_unmount_and_remove /var/lib/rancher/k3s
    + set +x
    + do_unmount_and_remove /var/lib/kubelet/pods
    + set +x
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/c9df0e84-cc5c-4907-ad27-39eef0e6a72b/volumes/kubernetes.io~projected/kube-api-access-srv4c 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/b686969e-ca63-4876-8a96-fcc5b13cb29b/volumes/kubernetes.io~projected/kube-api-access-xk25f 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/93264f7a-e28b-4e5e-be3a-ee8c77a1bad9/volumes/kubernetes.io~secret/values 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/93264f7a-e28b-4e5e-be3a-ee8c77a1bad9/volumes/kubernetes.io~projected/kube-api-access-z6k8g 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/6df544dd-c0de-4b2f-86b4-0090b769597e/volumes/kubernetes.io~projected/kube-api-access-5dx9h 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/02690ed2-3282-4862-b26b-0cc945f604ff/volumes/kubernetes.io~secret/values 
    sh -c umount "$0" && rm -rf "$0" /var/lib/kubelet/pods/02690ed2-3282-4862-b26b-0cc945f604ff/volumes/kubernetes.io~projected/kube-api-access-s9q7m 
    + do_unmount_and_remove /var/lib/kubelet/plugins
    + set +x
    + do_unmount_and_remove /run/netns/cni-
    + set +x
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-ed1ddc2c-bf65-4556-f501-f77f29cec8cd 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-d68f3528-4e0b-4fec-7627-cfc718bfd3b3 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-c1ff0b47-fbcd-6154-9817-bbcf67bfaf0a 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-7afe1f42-d8e3-9ad9-91f2-475d20ef2b38 
    sh -c umount "$0" && rm -rf "$0" /run/netns/cni-08b5aa4a-f98f-da08-2370-e4befff67913 
    + ip netns show
    + grep cni-
    + xargs -r -t -n 1 ip netns delete
    + remove_interfaces
    + ip link show
    + grep 'master cni0'
    + read ignore iface ignore
    + iface=veth2151d30d
    + '[' -z veth2151d30d ']'
    + ip link delete veth2151d30d
    + read ignore iface ignore
    + iface=veth535bfd02
    + '[' -z veth535bfd02 ']'
    + ip link delete veth535bfd02
    + read ignore iface ignore
    + iface=veth886e883e
    + '[' -z veth886e883e ']'
    + ip link delete veth886e883e
    Cannot find device "veth886e883e"
    + read ignore iface ignore
    + iface=veth95afd47d
    + '[' -z veth95afd47d ']'
    + ip link delete veth95afd47d
    Cannot find device "veth95afd47d"
    + read ignore iface ignore
    + ip link delete cni0
    + ip link delete flannel.1
    + ip link delete flannel-v6.1
    Cannot find device "flannel-v6.1"
    + ip link delete kube-ipvs0
    Cannot find device "kube-ipvs0"
    + ip link delete flannel-wg
    Cannot find device "flannel-wg"
    + ip link delete flannel-wg-v6
    Cannot find device "flannel-wg-v6"
    ++ command -v tailscale
    + '[' -n '' ']'
    + rm -rf /var/lib/cni/
    + iptables-save
    + grep -v KUBE-
    + grep -v CNI-
    + grep -iv flannel
    + iptables-restore
    + ip6tables-save
    + grep -v KUBE-
    + grep -v CNI-
    + grep -iv flannel
    + ip6tables-restore
    + command -v systemctl
    /usr/bin/systemctl
    + systemctl disable k3s
    Removed symlink /etc/systemd/system/multi-user.target.wants/k3s.service.
    + systemctl reset-failed k3s
    + systemctl daemon-reload
    + command -v rc-update
    + rm -f /etc/systemd/system/k3s.service
    + rm -f /etc/systemd/system/k3s.service.env
    + trap remove_uninstall EXIT
    + for cmd in kubectl crictl ctr
    + '[' -L /usr/local/bin/kubectl ']'
    + for cmd in kubectl crictl ctr
    + '[' -L /usr/local/bin/crictl ']'
    + rm -f /usr/local/bin/crictl
    + for cmd in kubectl crictl ctr
    + '[' -L /usr/local/bin/ctr ']'
    + rm -rf /etc/rancher/k3s
    + rm -rf /run/k3s
    + rm -rf /run/flannel
    + rm -rf /var/lib/rancher/k3s
    + rm -rf /var/lib/kubelet
    + rm -f /usr/local/bin/k3s
    + rm -f /usr/local/bin/k3s-killall.sh
    + type yum
    + yum remove -y k3s-selinux
    Loaded plugins: fastestmirror
    No Match for argument: k3s-selinux
    No Packages marked for removal
    + rm -f '/etc/yum.repos.d/rancher-k3s-common*.repo'
    + remove_uninstall
    + rm -f /usr/local/bin/k3s-uninstall.sh
    

    三,重新安装k3s

    但如果想重新安装k3s,可能不报错,但不能用。因为可能会报错。

    此时,将之前的几个可能的残留文件删除即可。

     1008  rm -rf /usr/local/bin/kubectl 
     1009  rm -rf /usr/local/bin/ctr
     1010  rm -rf /usr/bin/ctr
     1011  rm -rf /usr/local/bin/crictl
    

    (其实,这几个文件在重新安装k3s时,也会出现skipping的提示)

    [root@127 k3s]# cp ./k3s /usr/local/bin/
    [root@127 k3s]# INSTALL_K3S_SKIP_DOWNLOAD=true ./k3s-install.sh
    [INFO]  Skipping k3s download and verify
    [INFO]  Skipping installation of SELinux RPM
    [INFO]  Skipping /usr/local/bin/kubectl symlink to k3s, already exists
    [INFO]  Creating /usr/local/bin/crictl symlink to k3s
    [INFO]  Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
    [INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
    [INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
    [INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
    [INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
    [INFO]  systemd: Enabling k3s unit
    Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
    [INFO]  systemd: Starting k3s
    

    4,正常输出

    [root@127 ~]# kubectl get node
    NAME                                                         STATUS   ROLES                  AGE   VERSION
    127.0.0.1localhostlocalhost.localdomainlocalhost4localhost   Ready    control-plane,master   11m   v1.28.2+k3s1
    [root@127 ~]# kubectl get pod
    No resources found in default namespace.
    [root@127 ~]# kubectl get pod -all
    error: unknown shorthand flag: 'a' in -all
    See 'kubectl get --help' for usage.
    [root@127 ~]# kubectl get pod -A
    NAMESPACE     NAME                                      READY   STATUS      RESTARTS   AGE
    kube-system   local-path-provisioner-84db5d44d9-8hqrb   1/1     Running     0          10m
    kube-system   coredns-6799fbcd5-5kq2c                   1/1     Running     0          10m
    kube-system   metrics-server-67c658944b-r8gkc           1/1     Running     0          10m
    kube-system   helm-install-traefik-crd-h6ljc            0/1     Completed   0          10m
    kube-system   helm-install-traefik-6ctmg                0/1     Completed   2          10m
    kube-system   svclb-traefik-40b19ca2-x8bzl              2/2     Running     0          5m31s
    kube-system   traefik-7bf7d7576d-wm6ff                  1/1     Running     0          5m31s
    

    相关文章

      网友评论

          本文标题:离线重复安装k3s的tips

          本文链接:https://www.haomeiwen.com/subject/vbrrbdtx.html