【发布时间】:2019-11-26 08:25:46
【问题描述】:
我正在尝试使用 Kubernetes、一个已定义的服务和一个带有静态 ip 和 ssl 证书的入口将两个 nodejs 应用程序部署为两个独立的容器
我想使用 GCP 的 Kubernetes Engine 部署这些微服务。我添加的第二个微服务比另一个晚。 pod 中只有一个容器,一切正常。 我定义了三个 yaml 文件:deployment.yaml、service.yaml、ingress.yaml。
deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: qa-chatbot-backend-deployment
spec:
selector:
matchLabels:
app: service-backend1
replicas: 1
template:
metadata:
labels:
app: service-backend1
spec:
containers:
- name: serice-backend1
image: gcr.io/project-id/serice-backend1:v1.0.1
imagePullPolicy: Always
command: ["npm", "start"]
livenessProbe:
httpGet:
path: /
port: 8081
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 25
periodSeconds: 30
successThreshold: 1
failureThreshold: 2
readinessProbe:
httpGet:
path: /
port: 8081
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 25
periodSeconds: 30
successThreshold: 1
failureThreshold: 2
ports:
- name: service1-port
containerPort: 8081
- name: service-backend2
image: gcr.io/project-id/serice-backend2:v1.0.1
imagePullPolicy: Always
command: ["npm", "start"]
livenessProbe:
httpGet:
path: /api/test
port: 8082
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 25
periodSeconds: 30
successThreshold: 1
failureThreshold: 2
readinessProbe:
httpGet:
path: /api/test
port: 8082
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 25
periodSeconds: 30
successThreshold: 1
failureThreshold: 2
ports:
- name: service2-port
containerPort: 8082
service.yaml
apiVersion: v1
kind: Service
metadata:
name: service-kube
spec:
type: LoadBalancer
ports:
- targetPort: service1-port
port: 80
protocol: TCP
selector:
app: service-backend1
ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
labels:
app: service-backend1
name: ingress-kube
annotations:
kubernetes.io/ingress.global-static-ip-name: app-static-ip
spec:
tls:
- hosts:
- custom-host.com
secretName: custom-host-secret-name
rules:
- host: custom-host.com
http:
paths:
- backend:
serviceName: service-kube
servicePort: 80
使用此配置,只有一个服务可以访问,第一个
我尝试在 service.yaml 中添加多个端口
apiVersion: v1
kind: Service
metadata:
name: service-kube
spec:
type: LoadBalancer
ports:
- targetPort: service1-port
port: 80
protocol: TCP
- targetPort: service2-port
port: 80
protocol: TCP
selector:
app: service-backend1
但我收到一个错误。
The Service "service-kube" is invalid: spec.ports[1]: Duplicate value: core.ServicePort{Name:"", Protocol:"TCP", Port:80, TargetPort:intstr.IntOrString{Type:0, IntVal:0, StrVal:""}, NodePort:0}
我的目标是在域 custom-host.com 上公开两个后端;一个可在特定路径 (api/*) 上到达,另一个可到达所有可能的端点。
感谢您的帮助
【问题讨论】:
标签: kubernetes microservices kubernetes-ingress static-ip-address kubernetes-service