dubbo服務在kubernetes中對外暴露服務
阿新 • • 發佈:2019-03-20
一些場景下,在開發時可能存在dubbo consumer需要訪問k8s中部署的dubbo provider,尤其是對於自建的kubernetes叢集環境,tcp的埠很難代理,這就導致了開發發連結叢集內的服務比較麻煩,這裡可以利用service將dubbo服務使用nodeport暴露出去,但是由於dubbo預設註冊的ip地址是自動獲取服務的ip地址來註冊的,ip地址是pod的ip地址,叢集外是無法訪問的。幸運的是dubbo提供了自動義指定註冊ip的配置,我們可以在部署開發聯調服務時指定ip地址為宿主機的ip地址。部署例子如下:
# -------------------Service ---------------------- #
apiVersion: v1
kind: Service
metadata:
name: java-test-svc
namespace: default
spec:
type: NodePort
ports:
- port: 30011
targetPort: 30011
nodePort: 30011
selector:
app: java-test
tier: backend
---
# ------------------- Deployment ------------------- #
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: java-test-deployment
namespace: default
spec:
selector:
matchLabels:
app: java-test
tier: backend
replicas: 1
template:
metadata:
labels:
app: java-test
tier: backend
spec:
nodeSelector:
dubbo_provder: dubbo_provider
containers:
- name: java-test
image: [your image]
imagePullPolicy: Always
# resources:
# requests:
# cpu: 100m
# memory: 100Mi
# limits:
# cpu: 100m
# memory: 100Mi
env:
- name: APOLLO_META
value: http://172.31.205.22:8080
- name: DUBBO_IP_TO_REGISTRY
value: 172.31.205.23
- name: DUBBO_PORT_TO_REGISTRY
value: "30011"
- name: DUBBO_PORT_TO_BIND
value: "30011"
ports:
- containerPort: 30011
imagePullSecrets:
- name: harbor-key
---
# ------------------- ingress ---------------------- #
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: java-test-ingress
namespace: default
spec:
rules:
- host: javatest.com
http:
#port: 80
paths:
- path: /
backend:
serviceName: java-test-svc
service