# K8s、Linux、Docker相關雜記 ###### tags: `K8s` `Linux` `Docker` `IGL` --- [toc] ## K8s相關 ### 重新設定K8s - [Reference](https://www.akiicat.com/2019/04/26/Kubernetes/kubernetes-reinstall-on-ubuntu/) ### Kubernetes cluster 半手動建置 - [Reference](/QgH2_otuS3WaAVa8Wc82_Q) ### 完整移除K8s ```terminal kubeadm reset sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* sudo apt-get autoremove sudo rm -rf ~/.kube ``` - [Reference](https://stackoverflow.com/questions/44698283/how-to-completely-uninstall-kubernetes) ### 設定persistentvolume.yaml ``` apiVersion: v1 kind: PersistentVolume metadata: name: pvc-sonar spec: capacity: storage: 100Mi hostPath: path: >- /var/lib/k8s-pvs/sonar-claim0/pvc-sonar type: "" accessModes: - ReadWriteOnce claimRef: kind: PersistentVolumeClaim namespace: default name: sonar-claim0 storageClassName: hostpath ``` ### 增加node標籤、分派POD到指定node - [Reference](https://tachingchen.com/tw/blog/kubernetes-assigning-pod-to-nodes/) ### 修改主機hostname - [Reference](https://www.csdn.net/tags/MtTaMg5sNDkwMTEtYmxvZwO0O0OO0O0O.html) ### K8s部署步驟 - [Reference](https://hackmd.io/@zhouharry/SJokAY08p) ## Linux相關 ### 擴充硬碟空間 - LVM擴充步驟及指令: [Reference](https://godleon.github.io/blog/Linux/Linux-extend-lvm-from-unused-space/) - LVM概念: [Reference](https://linux.vbird.org/linux_basic_train/centos8/unit14.php#14.2) ### 查看服務運作 資訊 ```powershell systemctl status <service name> #EX:systemctl status kubelet ``` ### 安裝相關 - 確認安裝那些package ```terminal #確認安裝那些docker相關package dpkg -l | grep -i docker ``` - 解除安裝程式 ```terminal #安裝時使用apt-get的話 sudo apt-get remove -y <packeage name> #一般解除安裝 sudo apt-get purge -y <package name> #purge會把應用程式解除以及清除相關的設定檔 #EX:sudo apt-get purge -y kubectl ``` ```terminal #安裝時使用snap sudo snap remove <package name> sudo snap remove --purge <package name> ``` - 刪除sources list ```terminal #有兩種,可以都檢查 1. /etc/apt/sources.list #編輯裡面的內容 2. /etc/apt/sources.list.d/<package name>.list #刪除這個路徑的檔案 ``` - 固定安裝程式的版本 ```powershell apt-mark hold <package name> #EX(把Docker相關的所有安裝的程式固定版本):apt-mark hold docker* ``` ### Ubuntu壓縮、解壓縮 ```powershell #rar #需安裝相關套件(如果沒安裝,使用指令後會提示安裝) rar a Filename.rar DirName #壓縮 rar e Filename.rar #解壓縮 ``` ### Windows遠端從Linux下載檔案或上傳檔案到Linux(pscp) - 上傳 ```powershell #pscp <options> target <user@>host:source #pscp 要上傳檔案的位置 [選項] 使用者名稱@host ip或名稱:遠端存儲的位置 pscp D:\SmartCageCulture_俊弘\DCC_K8s_0425 master@140.121.101.181:/home/master/DCC_K8s ``` - 下載 ```powershell #pscp [options] user@host:source target #pscp [選項] 使用者名稱@host ip或名稱:要下載檔案的位置 本機存儲的位置 pscp jeremy@8.8.8.8:/home/user/picture.jpg c:/document/picture.jpg ``` ### 查看硬體規格指令  - [Reference](https://www.tokfun.net/os/linux/linux-hardware-information-command/) ### 查看程式運作的LOG ```terminal #查看kubelet的LOG journalctl -f -u kubelet ``` ### 清除bash 執行紀錄 ```terminal hash -d <package name> #EX: hash -d docker ``` - [Reference](https://forum.snapcraft.io/t/snap-bin-npm-no-such-file-or-directory-after-snap-remove-node-and-installing-node-via-apt/11981) ### Remove snap **注意: 執行此步驟要小心操作,避免失誤刪除整個系統** - 參見:[Link](https://askubuntu.com/questions/1280707/how-to-uninstall-snap) ## Docker相關 ### 查看Docker 資訊 ```terminal docker info ``` ### 完整刪除Docker ```terminal #uninstall old version sudo apt-get remove docker docker-engine docker.io containerd runc ``` ```terminal #uninstall Docker Engine sudo apt-get purge docker-ce docker-ce-cli containerd.io sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd ``` - [Reference1](https://docs.docker.com/engine/install/ubuntu/) - [Reference2](https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine) ### docker-registry - 部屬檔案 ```yml #docker-compose.yml version: '3' services: docker-registry: image: registry:2 container_name: docker-registry ports: - 5000:5000 restart: always volumes: - ./volume:/var/lib/registry docker-registry-ui: image: hyper/docker-registry-web container_name: docker-registry-ui links: - docker-registry ports: - 8080:8080 environment: REGISTRY_URL: http://docker-registry:5000/v2 REGISTRY_NAME: localhost:5000 ``` - 手動刪除images(參考用) ```terminal #步驟: 確定要刪除的repository的tags(可查看docker-registry網頁確認)-> # 查詢digest(確認要刪除的blobs、_manifest、_layers的編號(資料夾))-> # 刪除volume內的blobs、_manifest、_layers的檔案 #列出repository的tags curl 140.121.101.182:5000/v2/<imageName>/tags/list #取得tag的digest curl -X GET --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I http://140.121.101.182(181):5000/v2/<imageName>/manifests/<tag> #刪除指令 rm -rf <folderName(digest)> #相關路徑 blobs路徑: /<docker-compose.yml檔案路徑>/volume/docker/registry/v2/blobs _manifest、_layers路徑: /<docker-compose.yml檔案路徑>/volume/docker/registry/v2/repositories/<imageName>/_manifest、_layers ``` [Reference](https://www.gss.com.tw/blog/docker-registry-tag) ### docker-compose - 安裝 ```terminal sudo apt-cache madison docker-compose-plugin #尋找可安裝版本 sudo apt-get install docker-compose-plugin=<version> #EX:sudo apt-get install docker-compose-plugin=2.3.3~ubuntu-focal ``` [Reference](https://docs.docker.com/compose/install/#install-using-the-convenience-script) - 部屬container指令 ```terminal #強制重新生成docker container:--force-recreate #背景執行:--no-deps or -d #EX: docker-compose up --force-recreate --no-deps ```
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.