DevPill #3:如何将容器部署到您的 Kubernetes 集群(GKE)
发布: (2025年12月7日 GMT+8 06:22)
1 min read
原文: Dev.to
Source: Dev.to

部署清单
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-gateway
spec:
replicas: 1
selector:
matchLabels:
app: api-gateway
template:
metadata:
labels:
app: api-gateway
spec:
containers:
- name: api-gateway
image: us-central1-docker.pkg.dev///api-gateway
ports:
- containerPort: 8081
resources:
requests:
memory: "128Mi"
cpu: "125m"
limits:
memory: "128Mi"
cpu: "125m"
env:
# Accessing an env variable from the app-config config map
- name: GATEWAY_HTTP_ADDR
valueFrom:
configMapKeyRef:
name: app-config
key: GATEWAY_HTTP_ADDR
- name: JAEGER_ENDPOINT
valueFrom:
configMapKeyRef:
name: app-config
key: JAEGER_ENDPOINT
服务清单
apiVersion: v1
kind: Service
metadata:
name: api-gateway
spec:
type: LoadBalancer
ports:
- port: 8081
targetPort: 8081
selector:
app: api-gateway
部署到 GKE
-
访问 Google Cloud 控制台并创建你的 GKE 集群(这可能需要一些时间)。
-
获取集群凭据:
gcloud container clusters get-credentials --region us-central-1 --project -
上传清单文件:
kubectl apply -f infra/production/k8s/app-config.yaml kubectl apply -f infra/production/k8s/secrets.yaml kubectl apply -f infra/production/k8s/api-gateway-deployment.yaml -
检查部署的状态:
kubectl get deployments kubectl get pods