Skip to content

Latest commit

 

History

History
47 lines (39 loc) · 1.84 KB

5-2微服务应用-访问服务.md

File metadata and controls

47 lines (39 loc) · 1.84 KB

访问服务

对于服务的访问,先在Kubernetes集群内进行访问测试(通过Cluster IP访问) 当如上服务访问方式正常后,我们可以通过NodePort暴露给外部,然后使用浏览器进行访问测试

在kubenetes集群内访问测试

通过Cluster IP访问

[root@vms30 istio-lab] kubectl get svc
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service-lua      ClusterIP   10.99.146.20     <none>        80/TCP     34m

[root@vms30 istio-lab] curl http://10.99.146.20/env
{"message":"lua v2"}

在浏览器中访问测试

1)使用NodePort暴露服务。使用NodePort暴露sevice-js和service-python服务的v1版本

$ kubectl expose deployment service-js-v1 --type=NodePort --name=service-js-nodeport --port=80 --target-port=80
service/service-js-nodeport exposed

$ kubectl expose deployment service-python-v1 --type=NodePort --name=service-python-nodeport --port=80 --target-port=80
service/service-python-nodeport exposed

2)在浏览器中访问sevice-js和service-python服务 可以看到js端口在31148,python端口在32710 http://192.168.26.31:31148/env

获取service-js外部访问地址
[root@vms30 istio-lab]# kubectl get svc
NAME                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service-js-nodeport       NodePort    10.102.145.149   <none>        80:31148/TCP   7m56s
service-python-nodeport   NodePort    10.104.165.168   <none>        80:32710/TCP   7m46s

3)删除访问测试服务时创建的资源

kubectl delete service service-js-nodeport service-python-nodeport
kubectl delete -f service/go/service-go.yaml
kubectl delete -f service/node/service-node.yaml
kubectl delete -f service/lua/service-lua.yaml
kubectl delete -f service/python/service-python.yaml
kubectl delete -f service/js/service-js.yaml