管理服务¶
Snowpark Container Services 使您能够轻松部署、管理和扩展容器化应用程序。将应用程序镜像上传到账户中的存储库后,将应用程序容器作为服务或作业运行。本主题介绍如何使用服务。
服务是长期运行的,就像 Web 服务一样,不会自己结束。Snowflake 管理运行中的服务。例如,如果某个服务容器出于某种原因退出,Snowflake 会重新启动该容器,以便服务不间断地运行。如果您的服务需要更多的资源,例如更多的计算能力,Snowflake 会在计算池中预置额外的节点。
有关使用容器服务的详细信息,请参阅 Snowpark Container Services:使用服务。
本主题介绍如何使用服务执行以下任务:
对于常见操作,如列表或拖放,Snowflake CLI 使用 snow object
命令,如 管理 Snowflake 对象 中所述。
创建 Snowpark Container Services 服务¶
Snowpark Container Services 需要以下条件:
计算池:Snowflake 在指定的计算池中运行您的服务。
服务规范文件:此规范为 Snowflake 提供配置和运行服务所需的信息。
要创建服务,请输入类似于以下内容的 snow spcs service create 命令:
snow spcs service create "job_1" --compute-pool "pool_1" --spec-path "/some-dir/spec_file.yaml"
有关更多信息,请参阅 管理 Snowflake 对象。
暂停和恢复服务¶
要暂停命名服务,请输入类似于以下内容的 snow spcs service suspend 命令:
snow spcs service suspend echo_service
+-------------------------------------------+
| key | value |
|--------+----------------------------------|
| status | Statement executed successfully. |
+-------------------------------------------+
要恢复暂停服务,请输入类似于以下内容的 snow spcs service resume 命令:
snow spcs service resume echo_service
+-------------------------------------------+
| key | value |
|--------+----------------------------------|
| status | Statement executed successfully. |
+-------------------------------------------+
获取有关服务的状态信息¶
备注
当前角色必须对服务具有 MONITOR 权限才能获取服务状态。
列出所有服务¶
snow spcs service list 命令会返回所有服务的概述,包括服务的运行时状态,例如 PENDING 或 RUNNING,以及升级状态。要获取所有服务的状态,请输入类似于以下内容的命令:
snow spcs service list
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| | | | | | | | | | | | | extern | | | | | | | | | | | |
| | | | | | | | | | | | | al_acc | | | | | | | | | | managin | managi |
| | | databa | | | | | curren | target | min_in | max_in | | ess_in | | | | | owner_r | query_ | | | | g_objec | ng_obj |
| | | se_nam | schema | | comput | dns_na | t_inst | _insta | stance | stance | auto_re | tegrat | created | update | resumed | commen | ole_typ | wareho | | spec_di | is_upg | t_domai | ect_na |
| name | status | e | _name | owner | e_pool | me | ances | nces | s | s | sume | ions | _on | d_on | _on | t | e | use | is_job | gest | rading | n | me |
|--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+---------+--------+---------+--------+---------+--------+---------+--------+--------+---------+--------+---------+--------|
| ECHO_S | RUNNIN | TEST00 | TEST_S | SYSADM | TUTORI | echo-s | 1 | 1 | 1 | 1 | true | None | 2024-10 | 2024-1 | None | This | ROLE | COMPUT | false | 52e62d1 | false | None | None |
| ERVICE | G | _DB | CHEMA | IN | AL_COM | ervice | | | | | | | -16 | 0-16 | | is a | | E_WH | | f19c720 | | | |
| | | | | | PUTE_P | .imhd. | | | | | | | 15:09:3 | 15:09: | | test | | | | 6b5f4ef | | | |
| | | | | | OOL | svc.sp | | | | | | | 0.49300 | 31.905 | | servic | | | | c069557 | | | |
| | | | | | | cs.int | | | | | | | 0-07:00 | 000-07 | | e | | | | 8b6c2b3 | | | |
| | | | | | | ernal | | | | | | | | :00 | | | | | | 806ad76 | | | |
| | | | | | | | | | | | | | | | | | | | | 67d78cc | | | |
| | | | | | | | | | | | | | | | | | | | | ce8b6ed | | | |
| | | | | | | | | | | | | | | | | | | | | 6501a8a | | | |
| | | | | | | | | | | | | | | | | | | | | 3 | | | |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
获取命名服务的状态¶
要获取单个服务的状态,请输入类似于以下内容的 snow spcs service describe 命令:
snow spcs service describe echo_service
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| | | | | | | | | | | | | extern | | | | | | | | | | | |
| | | | | | | | | | | | | al_acc | | | | | | | | | | managin | managi |
| | | databa | | | | | curren | target | min_in | max_in | | ess_in | | | | | owner_r | query_ | | | | g_objec | ng_obj |
| | | se_nam | schema | | comput | dns_na | t_inst | _insta | stance | stance | auto_re | tegrat | created | update | resumed | commen | ole_typ | wareho | | spec_di | is_upg | t_domai | ect_na |
| name | status | e | _name | owner | e_pool | me | ances | nces | s | s | sume | ions | _on | d_on | _on | t | e | use | is_job | gest | rading | n | me |
|--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+---------+--------+---------+--------+---------+--------+---------+--------+--------+---------+--------+---------+--------|
| ECHO_S | RUNNIN | TEST00 | TEST_S | SYSADM | TUTORI | echo-s | 1 | 1 | 1 | 1 | true | None | 2024-10 | 2024-1 | None | This | ROLE | COMPUT | false | 52e62d1 | false | None | None |
| ERVICE | G | _DB | CHEMA | IN | AL_COM | ervice | | | | | | | -16 | 0-16 | | is a | | E_WH | | f19c720 | | | |
| | | | | | PUTE_P | .imhd. | | | | | | | 15:09:3 | 15:09: | | test | | | | 6b5f4ef | | | |
| | | | | | OOL | svc.sp | | | | | | | 0.49300 | 31.905 | | servic | | | | c069557 | | | |
| | | | | | | cs.int | | | | | | | 0-07:00 | 000-07 | | e | | | | 8b6c2b3 | | | |
| | | | | | | ernal | | | | | | | | :00 | | | | | | 806ad76 | | | |
| | | | | | | | | | | | | | | | | | | | | 67d78cc | | | |
| | | | | | | | | | | | | | | | | | | | | ce8b6ed | | | |
| | | | | | | | | | | | | | | | | | | | | 6501a8a | | | |
| | | | | | | | | | | | | | | | | | | | | 3 | | | |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
列出实例和容器¶
您可以分别使用 snow spcs service list-instances
和 snow spcs service list-containers
命令列出服务的实例和容器。
要获取 echo_service
服务中的实例列表,请输入以下 snow spcs service list-instances 命令:
snow spcs service list-instances echo_service
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| database_name | schema_name | service_name | instance_id | status | spec_digest | creation_time | start_time |
|---------------+-------------+--------------+-------------+--------+------------------------------------------------------------------+----------------------+----------------------|
| TEST00_DB | TEST_SCHEMA | ECHO_SERVICE | 0 | READY | 336c065739dd2b96e770f01804affdc7810e6df68a23b23052d851627abfbdf9 | 2024-10-10T06:06:30Z | 2024-10-10T06:06:30Z |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
要获取 echo_service
服务中的容器列表,请输入以下 snow spcs service list-containers 命令:
snow spcs service list-containers echo_service
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| database_name | schema_name | service_name | instance_id | container_name | status | message | image_name | image_digest | restart_count | start_time |
|---------------+-------------+--------------+-------------+----------------+--------+---------+-------------------------------------------+-------------------------------------------+---------------+----------------------|
| TEST00_DB | TEST_SCHEMA | ECHO_SERVICE | 0 | main | READY | Running | org-test-account-00.registry.registry.sno | sha256:06c3d54edc24925abe398eda70d37eb6b8 | 0 | 2024-10-16T22:09:35Z |
| | | | | | | | wflakecomputing.com/test00_db/test_schema | 7b1c4dd6211317592764e1e7d94498 | | |
| | | | | | | | /test00_repo/echo_service:latest | | | |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
列出服务中的端点¶
要列出命名服务的端点,请输入类似于以下内容的 snow spcs service list-endpoints 命令:
snow spcs service list-endpoints echo_service
+--------------+------+----------+-----------------+-----------------------------------------+
| name | port | protocol | ingress_enabled | ingress_url |
|--------------+------+----------+-----------------+-----------------------------------------|
| echoendpoint | 8000 | TCP | true | org-id-acct-id.snowflakecomputing.app |
+--------------+------+----------+-----------------+-----------------------------------------+
列出与服务关联的服务角色¶
您可以通过在服务规范中定义服务角色和权限来管理对服务公开的各个端点的访问权限。有关如何使用服务角色的更多信息,请参阅 GRANT SERVICE ROLE。
要获取为服务创建的服务角色列表,请使用 snow spcs service list-roles 命令,如下所示:
snow spcs service list-roles my_service
+------------------------------------------------------------------+
| created_on | name | comment |
|----------------------------------+---------------------+---------|
| 2024-10-09 16:48:52.980000-07:00 | ALL_ENDPOINTS_USAGE | None |
+------------------------------------------------------------------+
设置和取消设置服务的属性或参数¶
备注
当前角色必须具有该服务的 OPERATE 权限才能设置属性。
要设置服务的属性或参数,请输入类似于以下内容的 snow spcs service set 命令:
snow spcs service set echo_service --min-instances 2 --max-instances 4
+-------------------------------------------+
| key | value |
|--------+----------------------------------|
| status | Statement executed successfully. |
+-------------------------------------------+
要将服务的属性或参数重置为其默认值,请输入类似下面的命令:
snow spcs compute-pool unset tutorial_compute_pool --auto-resume
+-------------------------------------------+
| key | value |
|--------+----------------------------------|
| status | Statement executed successfully. |
+-------------------------------------------+
显示命名服务的日志¶
备注
当前角色必须具有对服务的 MONITOR 权限才能显示日志。
要显示命名服务的本地日志,请输入类似于以下内容的 snow spcs service logs 命令:
snow spcs service logs "service_1" --container-name "container_1" --instance-id "0"
升级命名服务¶
备注
当前角色必须具有对服务的 OPERATE 权限才能升级服务。
要升级命名服务,请输入类似于以下内容的 snow spcs service upgrade 命令:
snow spcs service upgrade echo_service --spec-path spec.yml
+-------------------------------------------+
| key | value |
|--------+----------------------------------|
| status | Statement executed successfully. |
+-------------------------------------------+