• K8S部署后的使用:dashboard启动、使用+docker镜像拉取、容器部署(ubuntu环境+gpu3080+3主机+部署深度学习模型)


    0、k8s安装、docker安装

    参考:前两步Ubuntu云原生环境安装,docker+k8s+kubeedge(亲测好用)_爱吃关东煮的博客-CSDN博客_ubantu部署kubeedge

     配置节点gpu:

    K8S调用GPU资源配置指南_思影影思的博客-CSDN博客_k8s 使用gpu

    1、重置和清除旧工程:每个节点主机都要运行

    1. kubeadm reset
    2. iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X

    2、部署新的k8s项目:

    只在主节点运行,apiserver-advertise-address填写主节点ip

    1. sudo kubeadm init \
    2. --apiserver-advertise-address=192.168.1.117 \
    3. --control-plane-endpoint=node4212 \
    4. --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
    5. --kubernetes-version v1.21.10 \
    6. --service-cidr=10.96.0.0/12 \
    7. --pod-network-cidr=10.244.0.0/16
    1. mkdir -p $HOME/.kube
    2. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    3. sudo chown $(id -u):$(id -g) $HOME/.kube/config

    主节点完成后,子节点运行主节点完成后展示的join命令

    3、装网络插件

    1. curl https://docs.projectcalico.org/manifests/calico.yaml -O
    2. kubectl apply -f calico.yaml

    等待完成

    4、装bashboard:主节点运行

    1. sudo kubectl apply -f /dashbord.yaml
    2. sudo kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
    3. type: ClusterIP 改为 type: NodePort
    1. # 找到端口,关闭对应防火墙
    2. sudo kubectl get svc -A |grep kubernetes-dashboard

    任意主机ip:31678为实际访问连接(https://192.168.1.109:31678/

     验证所有pod为run状态,否则检查前面步骤

    1. kubectl get pods --all-namespaces -o wide
    2. #查看pod状态
    3. kubectl describe pod kubernetes-dashboard-57c9bfc8c8-lmb67 --namespace kubernetes-dashboard
    4. #打印log
    5. kubectl logs nvidia-device-plugin-daemonset-xn7hx --namespace kube-system

    创建访问账号

    kubectl apply -f /dashuser.yaml

    获取访问令牌,在主节点运行,每天都会更新

    kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"

     填入token

    5、创建镜像并上传dockerhub:

    查看本地镜像:docker images

    登陆docker账户

    给docker打标签,左:本地名:tag 右hub用户名/仓库名:tag
    docker tag deeplabv3plus:1.0.0 chenzishu/deepmodel:labv3

    上传hub
    docker push chenzishu/deepmodel:labv3

    6、dashboard使用

     创建deployment

    应用名随意,镜像地址填写docherhub上对应镜像地址(chenzishu/deepmodel:pytorch)

    等待容器运行,需要时间

    1. ########
    2. #pod启动后一直重启,并报Back-off restarting failed container
    3. #找到对应的deployment添加
    4. command: ["/bin/bash", "-ce", "tail -f /dev/null"]
    5. ########

     

    7、运行pod:

    显示本地容器:docker ps -a 

    找到容器:

    kubectl get pods --all-namespaces -o wide

     进入容器:

    kubectl exec -it segnet-747b798bf5-4bjqk /bin/bash

    查看容器中文件:

    ls

     nvidia-smi查看容器是否可以调用gpu

    8、容器使用显卡资源,gpu资源分片

    https://gitcode.net/mirrors/AliyunContainerService/gpushare-scheduler-extender/-/blob/master/docs/install.md

    先安装nvidia-docker2:

    1. distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
    2. && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
    3. && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
    4. sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    5. sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

     

    1. sudo apt-get update
    2. sudo apt-get install -y nvidia-docker2
    3. sudo systemctl restart docker
    4. #测试
    5. sudo docker run --rm --gpus all nvidia/cuda:11.6.2-base-ubuntu20.04 nvidia-smi

    update可能会报错:参见官方文档Conflicting values set for option Signed-By error when running apt update

    1. E: Conflicting values set for option Signed-By regarding source https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64/ /: /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg !=
    2. E: The list of sources could not be read.

    解决方法:

    grep -l "nvidia.github.io" /etc/apt/sources.list.d/* | grep -vE "/nvidia-container-toolkit.list\$"

    删除列出的文件即可

    安装 gpushare-device-plugin 之前,确保在 GPU 节点上已经安装 Nvidia-Driver 以及 Nvidia-Docker2,同时已将 docker 的默认运行时设置为 nvidia:

    配置runtime:/etc/docker/daemon.json

    1. {
    2. "default-runtime": "nvidia",
    3. "runtimes": {
    4. "nvidia": {
    5. "path": "/usr/bin/nvidia-container-runtime",
    6. "runtimeArgs": []
    7. }
    8. }
    9. }

    GPU Sharing 部署

    再参考阿里开发文档,写的很详细 :配置、使用nvidia-share:https://developer.aliyun.com/article/690623

    K8S 集群使用阿里云 GPU sharing 实现 GPU 调度 - 点击领取 (dianjilingqu.com)

    部署 GPU 共享调度插件 gpushare-schd-extender

    1. cd /tmp/
    2. curl -O https://raw.githubusercontent.com/AliyunContainerService/gpushare-scheduler-extender/master/config/gpushare-schd-extender.yaml
    3. kubectl create -f gpushare-schd-extender.yaml
    4. # 需要能够在 master 上进行调度,在 gpushare-schd-extender.yaml 中将
    5. # nodeSelector:
    6. # node-role.kubernetes.io/master: ""
    7. # 这两句删除,使 k8s 能够在 master 上进行 GPU 调度
    8. ### 无法下载参考如下链接:
    9. wget http://49.232.8.65/yaml/gpushare-schd-extender.yaml

    部署设备插件 gpushare-device-plugin

    1. cd /tmp/
    2. wget https://raw.githubusercontent.com/AliyunContainerService/gpushare-device-plugin/master/device-plugin-rbac.yaml
    3. kubectl create -f device-plugin-rbac.yaml
    4. wget https://raw.githubusercontent.com/AliyunContainerService/gpushare-device-plugin/master/device-plugin-ds.yaml
    5. # 默认情况下,GPU 显存以 GiB 为单位,若需要使用 MiB 为单位,需要在这个文件中,将 --memory-unit=GiB 修改为 --memory-unit=MiB
    6. kubectl create -f device-plugin-ds.yaml
    7. ### 无法下载参考如下链接:
    8. wget http://49.232.8.65/yaml/device-plugin-rbac.yaml
    9. wget http://49.232.8.65/yaml/device-plugin-ds.yaml

      为 GPU 节点打标签

    1. # 为了将 GPU 程序调度到带有 GPU 的服务器,需要给服务打标签 gpushare=true
    2. kubectl get nodes
    3. # 选取 GPU 节点打标
    4. kubectl label node <target_node> gpushare=true
    5. kubectl describe node <target_node>

    更新 kubectl 可执行程序

    1. wget https://github.com/AliyunContainerService/gpushare-device-plugin/releases/download/v0.3.0/kubectl-inspect-gpushare
    2. chmod u+x kubectl-inspect-gpushare
    3. mv kubectl-inspect-gpushare /usr/local/bin
    4. ### 无法下载参考如下链接:
    5. wget http://49.232.8.64/k8s/kubectl-inspect-gpushare

     查看 GPU 信息:若能看到 GPU 信息,则代表安装成功

    1. root@dell21[/root]# kubectl inspect gpushare
    2. NAME IPADDRESS GPU0(Allocated/Total) PENDING(Allocated) GPU Memory(GiB)
    3. 10.45.61.22 10.45.61.22 0/7 2 2/7
    4. ------------------------------------------------------
    5. Allocated/Total GPU Memory In Cluster:
    6. 2/7 (28%)

    9、部分问题

    pod无法启动、资源不足

    1. #设置污点阈值
    2. systemctl status -l kubelet
    3. #文件路径
    4. /etc/systemd/system/kubelet.service.d/
    5. #放宽阈值
    6. #修改配置文件增加传参数,添加此配置项 --eviction-hard=nodefs.available<3%
    7. Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --eviction-hard=nodefs.available<3%"
    8. systemctl daemon-reload
    9. systemctl restart kubelet

    pod反复重启:

    1. pod启动后一直重启,并报Back-off restarting failed container
    2. 找到对应的deployment
    3. command: ["/bin/bash", "-ce", "tail -f /dev/null"]
    4. spec:
    5. containers:
    6. - name: test-file
    7. image: xxx:v1
    8. command: ["/bin/bash", "-ce", "tail -f /dev/null"]
    9. imagePullPolicy: IfNotPresent

  • 相关阅读:
    代理IP协议有何区别?深入了解 SOCKS5、HTTP 代理
    9.20金融科技(比特币)
    【算法 】两组随机变量协方差矩阵 矩阵的特征值与特征向量
    文件系统系列专题之 Ext2/3/4
    富文本编辑器的实现与回显
    【桥接设计模式详解】Java/JS/Go/Python/TS不同语言实现
    zabbix监控
    中秋不加班,猿人永不屈服!!! So,How to celebrate the Mid Autumn Festival?
    Python系列(20)—— 排序算法
    法院判错案如何追责?
  • 原文地址:https://blog.csdn.net/weixin_43863744/article/details/128034981