本文介绍如何在阿里云容器平台 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

在集群治理页左侧导航栏中,选择网络 > 服务。

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

期待约 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/v1kind: Deploymentmetadata:  labels:    app: stable-diffusion  name: stable-diffusion  namespace: defaultspec:  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: v1kind: Servicemetadata:  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: defaultspec:  externalTrafficPolicy: Local  ports:  - port: 7860    protocol: TCP    targetPort: 7860  selector:    app: stable-diffusion  type: LoadBalancer

期待 pod ready

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

# 查看pod状态,期待pod runningkubectl get po |grep stable-diffusion# 查看CLB IPkubectl get svc stable-diffusionNAME               TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)          AGEstable-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/v1kind: Deploymentmetadata:  labels:    app: stable-diffusion  name: stable-diffusion  namespace: defaultspec:  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: v1kind: Servicemetadata:  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: defaultspec:  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 runningkubectl get po |grep stable-diffusion# 查看CLB IPkubectl get svc stable-diffusionNAME               TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)          AGEstable-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 日
镜像仓库地址:http://zibai-registry.cn-hangzhou.cr.aliyuncs.com/gpt/stable-...

相干链接:

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=htt...

[4] 创立托管 GPU 集群

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

作者:子白

原文链接

本文为阿里云原创内容,未经容许不得转载。