我正在尝试使用端口 8888 加载服务,但由于某种原因,只有端口 80 有效,而使用端口 8888 无法访问该站点。
配置如下:
kind: Service
apiVersion: v1
metadata:
name: ingress-nginx
labels:
k8s-addon: ingress-nginx.addons.k8s.io
annotations:
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
spec:
type: LoadBalancer
selector:
app: ingress-nginx
ports:
- name: http
port: 80
targetPort: http
- name: https
port: 443
targetPort: https
- name: port8888
port: 8888
targetPort: 8888
---
kind: ConfigMap
apiVersion: v1
metadata:
name: ingress-nginx
labels:
k8s-addon: ingress-nginx.addons.k8s.io
data:
use-proxy-protocol: "true"
8888: "default/some-api:8888"
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: ingress-nginx
labels:
k8s-addon: ingress-nginx.addons.k8s.io
spec:
replicas: 1
template:
metadata:
labels:
app: ingress-nginx
k8s-addon: ingress-nginx.addons.k8s.io
spec:
terminationGracePeriodSeconds: 60
containers:
- image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.11
name: ingress-nginx
imagePullPolicy: Always
ports:
- name: http
containerPort: 80
protocol: TCP
- name: https
containerPort: 443
protocol: TCP
- name: port8888
containerPort: 8888
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
args:
- /nginx-ingress-controller
- --default-backend-service=$(POD_NAMESPACE)/nginx-default-backend
- --configmap=$(POD_NAMESPACE)/ingress-nginx
- --publish-service=$(POD_NAMESPACE)/ingress-nginx
该行8888: "default/some-api:8888"
与入口示例一致,如下所示:https ://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/examples/tcp/tcp-configmap-example.yaml
我还将端口 8888 添加到负载均衡器和部署本身的端口列表中。
该服务的代码是:
apiVersion: v1
kind: Service
metadata:
name: some-api
labels:
name: some-api
spec:
ports:
- port: 8888
selector:
name: some-api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: some-api-dply
spec:
replicas: 1
template:
metadata:
labels:
name: some-api
spec:
containers:
- name: some-api-container
image: [url-ommited]
ports:
- containerPort: 8888
hostPort: 8888
注意:在 AWS 中,在 Load Balancer 的 Listeners 页面中,配置设置为:
LB Protocol | Port | Inst. Protocol | Inst. Port
TCP | 8888 | TCP | 32585
入口代码如下所示:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/rewrite-target: /
name: rewrite
namespace: default
spec:
rules:
- host: "*.elb.amazonaws.com"
http:
paths:
- backend:
serviceName: some-api
servicePort: 8888
path: /