---
# System prepended metadata

title: ubuntu 指定下載 kubeadm & CRI-O 套件，上傳至 Nexus
tags: [工具]

---

# ubuntu 指定下載 kubeadm & CRI-O 套件，上傳至 Nexus



* 指定 k8s 版本以及 crio 版本
```
$ KUBERNETES_VERSION=v1.29
$ CRIO_STREAM="stable:/v1.29"

$ curl -fsSL "https://pkgs.k8s.io/core:/stable:/${KUBERNETES_VERSION}/deb/Release.key" \
  | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

$ echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/${KUBERNETES_VERSION}/deb/ /" \
  | sudo tee /etc/apt/sources.list.d/kubernetes.list


$ curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/${CRIO_STREAM}/deb/Release.key |
    sudo gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg

$ echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://pkgs.k8s.io/addons:/cri-o:/${CRIO_STREAM}/deb/ /" |
    sudo tee /etc/apt/sources.list.d/cri-o.list
```

* 更新 apt index
```
$ sudo apt-get update
```

* 下載（只下載，不安裝），把快取檔放到你指定的 WORKDIR
```
$ mkdir /home/bigred/kube-1.29

$ sudo apt-get -y --download-only -o Dir::Cache::archives="/home/bigred/kube-1.29" install crun cri-o=1.29.2-1.1 kubelet=1.29.3-1.1 kubeadm=1.29.3-1.1 kubectl=1.29.3-1.1

$ ls -l kube-1.29/
total 109604
-rw-r--r-- 1 root root    37856 Apr  5  2024 conntrack_1%3a1.4.8-1ubuntu1_amd64.deb
-rw-r--r-- 1 root root 19325188 Feb 23  2024 cri-o_1.29.2-1.1_amd64.deb
-rw-r--r-- 1 root root 20134148 Dec 12  2023 cri-tools_1.29.0-1.1_amd64.deb
-rw-r--r-- 1 root root   405538 Feb 15  2024 crun_1.14.1-1_amd64.deb
-rw-r--r-- 1 root root    88430 Apr  1  2024 ebtables_2.0.11-6build1_amd64.deb
-rw-r--r-- 1 root root 10097832 Mar 16  2024 kubeadm_1.29.3-1.1_amd64.deb
-rw-r--r-- 1 root root 10507996 Mar 16  2024 kubectl_1.29.3-1.1_amd64.deb
-rw-r--r-- 1 root root 19826884 Mar 16  2024 kubelet_1.29.3-1.1_amd64.deb
-rw-r--r-- 1 root root 31387200 Dec 13  2023 kubernetes-cni_1.3.0-1.1_amd64.deb
-rw-r--r-- 1 root root    20202 Apr  9  2024 libyajl2_2.1.0-5build1_amd64.deb
-rw-r----- 1 root root        0 Sep 25 15:31 lock
drwx------ 2 _apt root     4096 Sep 25 15:31 partial
-rw-r--r-- 1 root root   373594 Apr  8  2024 socat_1.8.0.0-4build3_amd64.deb
```

* 透過 api 將 deb 檔上傳到 Nexus
```
$ cd kube-1.29/

$ curl -u 'admin:!QAZ2wsx@WSX!!' -H "Content-Type: multipart/form-data" --data-binary "@./conntrack_1%3a1.4.8-1ubuntu1_amd64.deb" "http://10.10.7.20:8081/repository/apt-host/"
```
```
$ cat push_pk.sh
#!/bin/bash
#set -x

RED='\033[1;31m' # alarm
GRN='\033[1;32m' # notice
YEL='\033[1;33m' # warning
NC='\033[0m' # No Color


NEXUS_URL=http://10.10.7.20:8081
NEXUS_USER=admin
NEXUS_PASSWD=!QAZ2wsx@WSX!!
NEXUS_BROWSE=apt-host


while IFS= read -r line
do
  curl -u "${NEXUS_USER}:${NEXUS_PASSWD}" -H "Content-Type: multipart/form-data" --data-binary "@./${line}" "${NEXUS_URL}/repository/${NEXUS_BROWSE}/" &>/dev/null
  if [[ "$?" == 0 ]]; then
    printf "${GRN}Push ${line} success${NC}\n"
  else
    printf "${RED}Push ${line} fail${NC}\n"
  fi
done < <(ls $pwd | grep .deb)
```
## 在 ubuntu(client) 安裝套件

```
$ sudo apt-cache madison kubelet kubeadm kubectl crun cri-o
```

```
$ sudo apt install -y crun cri-o=1.29.2-1.1 kubelet=1.29.3-1.1 kubeadm=1.29.3-1.1 kubectl=1.29.3-1.1
```



* 啟動 crio
```
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now crio.service
```










