关于阿里云:基于容器平台-ACK-快速搭建-Stable-Diffusion

2次阅读

共计 3830 个字符,预计需要花费 10 分钟才能阅读完成。

作者:子白

本文介绍如何在阿里云容器平台 ACK 上疾速搭建一套可对外提供服务的 Stable Diffusion。

CPU 版本

前提条件

  • 已创立 Kubernetes 托管版集群。具体操作,请参见创立 Kubernetes 托管版集群[1]。

📍无需 GPU,节点须要 8c16g 以上

  • 已通过 kubectl 连贯 kubernetes 集群。具体操作,请参见 通过 Kubectl 连贯 Kubernetes 集群 [ 2]

应用控制台创立

  1. 登录容器服务治理控制台[3],在左侧导航栏抉择集群。
  2. 在集群列表页面中,单击指标集群名称或者指标集群右侧操作列下的详情。
  3. 在集群治理页左侧导航栏中,抉择 工作负载 > 无状态
  4. 无状态 页面中,单击 应用镜像创立
  5. 利用根本信息 配置向导页面中,设置利用的根本信息。

zibai-registry.cn-hangzhou.cr.aliyuncs.com/gpt/stable-diffusion:v1.cpu

["python3", "launch.py"]
["--listen", "--skip-torch-cuda-test", "--no-half"]

期待 pod ready

📍镜像大小为 12.7GB,内网下载约 10min

  1. 在集群治理页左侧导航栏中,抉择 网络 > 服务

新建服务,抉择负载平衡类型。

期待约 1min 后,刷新页面能够看到 External IP 列有具体 IP

在浏览器中拜访上一步获取到的 http://xxx.xxx.xxx.xxx:7860,即可看到如下页面。

Prompt:Black and white photo of a beautiful city

Sampling method:DPM++ SDE

应用 kubectl 创立

stable-diffusion.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: stable-diffusion
  name: stable-diffusion
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: stable-diffusion
  template:
    metadata:
      labels:
        app: stable-diffusion
    spec:
      containers:
      - args:
        - --listen
        - --skip-torch-cuda-test
        - --no-half
        command:
        - python3
        - launch.py
        image: zibai-registry.cn-hangzhou.cr.aliyuncs.com/gpt/stable-diffusion:v1.cpu
        imagePullPolicy: IfNotPresent
        name: stable-diffusion
        resources:
          requests:
            cpu: "2"
            memory: 2Gi
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-instance-charge-type: PayByCLCU
  name: stable-diffusion
  namespace: default
spec:
  externalTrafficPolicy: Local
  ports:
  - port: 7860
    protocol: TCP
    targetPort: 7860
  selector:
    app: stable-diffusion
  type: LoadBalancer
kubectl apply -f stable-diffusion.yaml

期待 pod ready

📍镜像大小为 12.7GB,内网下载约 10min

# 查看 pod 状态,期待 pod running
kubectl get po |grep stable-diffusion

# 查看 CLB IP
kubectl get svc stable-diffusion

NAME               TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)          AGE
stable-diffusion   LoadBalancer   192.168.x.x     xx.xx.xx.xxx   7860:32320/TCP   12m

在浏览器中拜访上一步获取到的 http://xxx.xxx.xxx.xxx:7860,即可看到如下页面。

Prompt:Black and white photo of a beautiful city

Sampling method:DPM++ SDE

GPU 版本

前提条件

  • 已创立 Kubernetes 异构集群集群。具体操作,请参见创立托管 GPU 集群[4]。

📍须要 GPU 节点,磁盘残余容量需大于 40G

  • 已通过 kubectl 连贯 kubernetes 集群。具体操作,请参见通过 Kubectl 连贯 Kubernetes 集群。

应用 kubectl 创立

stable-diffusion.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: stable-diffusion
  name: stable-diffusion
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: stable-diffusion
  template:
    metadata:
      labels:
        app: stable-diffusion
    spec:
      containers:
      - args:
        - --listen
        command:
        - python3
        - launch.py
        image: zibai-registry.cn-hangzhou.cr.aliyuncs.com/gpt/stable-diffusion:v1.gpu
        imagePullPolicy: IfNotPresent
        name: stable-diffusion
        resources:
          requests:
            cpu: "2"
            memory: 2Gi
          limits:
            nvidia.com/gpu: 1
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
    service.beta.kubernetes.io/alibaba-cloud-loadbalancer-instance-charge-type: PayByCLCU
  name: stable-diffusion
  namespace: default
spec:
  externalTrafficPolicy: Local
  ports:
  - port: 7860
    protocol: TCP
    targetPort: 7860
  selector:
    app: stable-diffusion
  type: LoadBalancer
kubectl apply -f stable-diffusion.yaml

期待 pod ready

📍镜像大小为 15.1GB,内网下载约 15min

# 查看 pod 状态,期待 pod running
kubectl get po |grep stable-diffusion

# 查看 CLB IP
kubectl get svc stable-diffusion

NAME               TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)          AGE
stable-diffusion   LoadBalancer   192.168.x.x     xx.xx.xx.xxx   7860:32320/TCP   12m

在浏览器中拜访上一步获取到的 http://xxx.xxx.xxx.xxx:7860,即可看到如下页面。

Prompt:Black and white photo of a beautiful city

Sampling method:DPM++ SDE

GPU 版本的图片生成速度显著优于 CPU 版本。

注:镜像可拉取工夫截止至 2023 年 5 月 17 日

镜像仓库地址:zibai-registry.cn-hangzhou.cr.aliyuncs.com/gpt/stable-diffusion

相干链接:

https://github.com/AUTOMATIC1111/stable-diffusion-webui

[1] 创立 Kubernetes 托管版集群

https://help.aliyun.com/document_detail/95108.htm#task-skz-qw…

[2] 通过 Kubectl 连贯 Kubernetes 集群

https://help.aliyun.com/document_detail/86494.htm#task-ubf-lh…

[3] 容器服务治理控制台

https://account.aliyun.com/login/login.htm?oauth_callback=https%3A%2F%2Fcs.console.aliyun.com%2F

[4] 创立托管 GPU 集群

https://help.aliyun.com/document_detail/171074.html?spm=a2c4g…

点击此处即可查看容器服务 ACK 产品详情

正文完
 0