思考
- k8s中不同类型的pod之间如何相互访问?
- 例如web服务如何访问db服务?
资料下载
下载地址:https://www.qstack.com.cn/tomcat_demo.zip
解压unzip tomcat_demo.zip
[root@k8s-master k8s]# ls tomcat_demo
mysql-rc.yml mysql-svc.yml tomcat-rc.yml tomcat-svc.yml
操作演示
[root@k8s-master tomcat_demo]# kubectl create -f mysql-rc.yml
replicationcontroller "mysql" created
[root@k8s-master tomcat_demo]# kubectl create -f mysql-svc.yml
service "mysql" created
[root@k8s-master tomcat_demo]# kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> 443/TCP 6d
mysql 10.254.155.23 <none> 3306/TCP 4s
[root@k8s-master tomcat_demo]# vim tomcat-rc.yml
- name: MYSQL_SERVICE_HOST
value: '10.254.155.23'
[root@k8s-master tomcat_demo]# kubectl create -f tomcat-rc.yml
replicationcontroller "myweb" created
[root@k8s-master tomcat_demo]#
[root@k8s-master tomcat_demo]# kubectl create -f tomcat-svc.yml
service "myweb" created
测试访问
访问地址http://10.0.0.12:30008/demo/