Skip to content

Commit f7359e3

Browse files
sasha-gitgcopybara-github
authored andcommitted
fix: Default to ClusterIP so GKE deployment isn't publicly exposed by default
Co-authored-by: Sasha Sobran <asobran@google.com> PiperOrigin-RevId: 890025323
1 parent ab9ae0f commit f7359e3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/google/adk/cli/cli_deploy.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import sys
2323
import traceback
2424
from typing import Final
25+
from typing import Literal
2526
from typing import Optional
2627
import warnings
2728

@@ -1170,6 +1171,9 @@ def to_gke(
11701171
memory_service_uri: Optional[str] = None,
11711172
use_local_storage: bool = False,
11721173
a2a: bool = False,
1174+
service_type: Literal[
1175+
'ClusterIP', 'NodePort', 'LoadBalancer'
1176+
] = 'ClusterIP',
11731177
):
11741178
"""Deploys an agent to Google Kubernetes Engine(GKE).
11751179
@@ -1197,6 +1201,7 @@ def to_gke(
11971201
artifact_service_uri: The URI of the artifact service.
11981202
memory_service_uri: The URI of the memory service.
11991203
use_local_storage: Whether to use local .adk storage in the container.
1204+
service_type: The Kubernetes Service type (default: ClusterIP).
12001205
"""
12011206
click.secho(
12021207
'\n🚀 Starting ADK Agent Deployment to GKE...', fg='cyan', bold=True
@@ -1334,7 +1339,7 @@ def to_gke(
13341339
metadata:
13351340
name: {service_name}
13361341
spec:
1337-
type: LoadBalancer
1342+
type: {service_type}
13381343
selector:
13391344
app: {service_name}
13401345
ports:
@@ -1388,3 +1393,11 @@ def to_gke(
13881393
click.secho(
13891394
'\n🎉 Deployment to GKE finished successfully!', fg='cyan', bold=True
13901395
)
1396+
if service_type == 'ClusterIP':
1397+
click.echo(
1398+
'\nThe service is only reachable from within the cluster.'
1399+
' To access it locally, run:'
1400+
f'\n kubectl port-forward svc/{service_name} {port}:{port}'
1401+
'\n\nTo expose the service externally, add a Gateway or'
1402+
' re-deploy with --service_type=LoadBalancer.'
1403+
)

src/google/adk/cli/cli_tools_click.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,17 @@ def cli_deploy_agent_engine(
22382238
default="INFO",
22392239
help="Optional. Set the logging level",
22402240
)
2241+
@click.option(
2242+
"--service_type",
2243+
type=click.Choice(["ClusterIP", "LoadBalancer"], case_sensitive=True),
2244+
default="ClusterIP",
2245+
show_default=True,
2246+
help=(
2247+
"Optional. The Kubernetes Service type for the deployed agent."
2248+
" ClusterIP (default) keeps the service cluster-internal;"
2249+
" use LoadBalancer to expose a public IP."
2250+
),
2251+
)
22412252
@click.option(
22422253
"--temp_folder",
22432254
type=str,
@@ -2281,6 +2292,7 @@ def cli_deploy_gke(
22812292
otel_to_cloud: bool,
22822293
with_ui: bool,
22832294
adk_version: str,
2295+
service_type: str,
22842296
log_level: Optional[str] = None,
22852297
session_service_uri: Optional[str] = None,
22862298
artifact_service_uri: Optional[str] = None,
@@ -2312,6 +2324,7 @@ def cli_deploy_gke(
23122324
with_ui=with_ui,
23132325
log_level=log_level,
23142326
adk_version=adk_version,
2327+
service_type=service_type,
23152328
session_service_uri=session_service_uri,
23162329
artifact_service_uri=artifact_service_uri,
23172330
memory_service_uri=memory_service_uri,

tests/unittests/cli/utils/test_cli_deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def mock_subprocess_run(*args, **kwargs):
508508
assert "image: gcr.io/gke-proj/gke-svc" in yaml_content
509509
assert f"containerPort: 9090" in yaml_content
510510
assert f"targetPort: 9090" in yaml_content
511-
assert "type: LoadBalancer" in yaml_content
511+
assert "type: ClusterIP" in yaml_content
512512

513513
# 4. Verify cleanup
514514
assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path)

0 commit comments

Comments
 (0)