1.dubbo配置:
dubbo.application.name=demo
dubbo.registry.address=zookeeper://192.168.40.170:2181 # 这里需要改成本机的IP地址
dubbo.spring.config=classpath*:spring/provider.xml
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
2.Dockerfile文件内容:
FROM hub.yangtuojia.com/kubernetes/openjdk:8-jre-slim-buster
COPY target/ROOT /ROOT
ENTRYPOINT [“sh”,"/ROOT/bin/start.sh"]
3.服务发现和k8s中的配置:
#deploy
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubb-demo
spec:
selector:
matchLabels:
app: dubb-demo
replicas: 1
template:
metadata:
labels:
app: dubb-demo
spec:
hostNetwork: true
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- dubb-demo
topologyKey: "kubernetes.io/hostname"
containers:
- name: dubb-demo
image: hub.yangtuojia.com/kubernetes/dubbo:v1
ports:
- containerPort: 20881
env:
- name: DUBBO_PORT
value: "20881"
4.pod的状态:
[root@m1 configs]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cronjob-demo-1617801180-m98lj 0/1 Completed 0 2m42s 172.22.4.39 s2
cronjob-demo-1617801240-rbxc7 0/1 Completed 0 102s 172.22.4.40 s2
cronjob-demo-1617801300-l2dm9 0/1 Completed 0 42s 172.22.4.41 s2
dubb-demo-95f6cc844-2tmls 1/1 Running 0 59s 192.168.40.181 s2
5.进入容器看端口配置状态:
*[root@m1 conf]# kubectl exec -it dubb-demo-95f6cc844-dzh6t /bin/bash
root@s1:/# ls
ROOT bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@s1:/# cd ROOT/
root@s1:/ROOT# ls
bin conf lib logs
root@s1:/ROOT# cd conf/
root@s1:/ROOT/conf# ls
dubbo.properties log4j.xml spring
root@s1:/ROOT/conf# cat dubbo.properties
dubbo.application.name=demo
dubbo.registry.address=zookeeper://192.168.40.170:2181
dubbo.spring.config=classpath:spring/provider.xml
dubbo.protocol.name=dubbo
dubbo.protocol.port=
这里的端口配置变成了空。
这个是什么原因呢?**
6.看对应的宿主机上面的监听状态:
[root@s1 ~]# netstat -tunlp | grep 20
tcp 0 0 0.0.0.0:20880 0.0.0.0:* LISTEN 105333/java
[root@s1 ~]# ip ro sh
default via 192.168.40.1 dev eth0 proto static metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
172.22.0.0/24 via 192.168.40.170 dev tunl0 proto bird onlink
172.22.1.0/24 via 192.168.40.171 dev tunl0 proto bird onlink
172.22.2.0/24 via 192.168.40.172 dev tunl0 proto bird onlink
blackhole 172.22.3.0/24 proto bird
172.22.3.7 dev calif8f32915d8c scope link
172.22.3.8 dev cali1b162cc812b scope link
172.22.3.223 dev calie6156c98b1d scope link
192.168.40.0/24 dev eth0 proto kernel scope link src 192.168.40.180 metric 100
为啥这里监听了20880,实在有点不理解。
帮忙看看。