You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes新手求助:如何将Pod暴露至外部流量?

Kubernetes新手配置Service与Ingress的疑问

我是Kubernetes新手,使用Docker Desktop搭建了集群,其中有一个运行后端服务的Pod。我了解Service可关联Pod并提供静态IP以实现外部流量访问(希望通过浏览器访问后端),但不知具体操作,网上资料也难以理解。我认为需要将Service设置为LoadBalancer类型来分配静态IP转发流量至Pod(当前仅1个副本,测试成功后将扩容),但尝试后无法正常工作,以下是相关配置文件:

Deployment配置

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: my-app
  name: my-app
spec:
  selector:
    matchLabels:
      app: my-app
  replicas: 1
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: my-app/my-app
        imagePullPolicy: IfNotPresent
        env:
        - name: GET_HOSTS_FROM
          value: dns
        - name: DATABASE_URL
          value: postgres://postgres:postgres@database/postgres
        ports:
        - containerPort: 80

Service配置

apiVersion: v1
kind: Service
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  ports:
  - port: 80
    targetPort: 8080 
  selector:
    app: my-app

我最终希望将服务部署至AWS或GCP,但目前不知下一步如何操作,恳请提供指导或学习资料。另外我添加了Ingress配置,但不确定与Service关联后的预期效果,配置如下:

Ingress配置

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-srv
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  ingressClassName: nginx
  rules:
    - host: lesser-bank.com
      http:
        paths:
          - pathType: Prefix
            path: "/test"
            backend:
              service:
                name: lesser-bank-api
                port:
                  number: 8080

内容的提问来源于stack exchange,提问作者lev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 07:12:15