加入收藏 | 设为首页 | 会员中心 | 我要投稿 晋中站长网 (https://www.0354zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

一个简单的Kubernetes应用部署示例

发布时间:2019-11-09 02:08:07 所属栏目:MySql教程 来源:云计算AND容器技术
导读:说明 我们通过一个简单的示例来说明如何在Kubernets中部署一个应用, 一个Spring Boot项目提供数据库的增删改查操作 一个Mysql数据库持久化数据 通过Eclipse构建一个Spring Boot项目以下简称demo,其中连接mysql的property文件application-k8s.properties

通过restful api向数据库写入测试数据

  1. curl -X POST "http://10.0.0.10:8001/api/v1/namespaces/default/services/demo/proxy/service/v1/user" -H "accept: application/json" -H "Content-Type: application/json" -d "{ "birthDay": "2019-03-31T04:03:43.259Z", "createDate": "2019-03-31T04:03:43.259Z", "email": "A1@test.com", "name": "A1", "sex": 0}" 
  2. success 
  3. ​ 
  4. curl -X POST "http://10.0.0.10:8001/api/v1/namespaces/default/services/demo/proxy/service/v1/user" -H "accept: application/json" -H "Content-Type: application/json" -d "{ "birthDay": "2019-03-31T04:03:43.259Z", "createDate": "2019-03-31T04:03:43.259Z", "email": "B2@test.com", "name": "B2", "sex": 1}" 
  5. success  

通过restful api查询刚才写入的数据

  1. curl -X GET "http://10.0.0.10:8001/api/v1/namespaces/default/services/demo/proxy/service/v1/users" -H "accept: application/json" 
  2. [{"id":1,"name":"A1","email":"A1@test.com","sex":0,"birthDay":"2019-03-31T04:03:43.000+0000","createDate":"2019-03-31T04:03:43.000+0000"},{"id":2,"name":"B2","email":"B2@test.com","sex":1,"birthDay":"2019-03-31T04:03:43.000+0000","createDate":"2019-03-31T04:03:43.000+0000"}] 

可以看到已经查询到刚才写入的测试数据。

通过命令行查看数据库的数据

  1. kubectl get pod 
  2. NAME READY STATUS RESTARTS AGE 
  3. demo-d4cd5bfdd-8qpfw 1/1 Running 0 7m54s 
  4. mysql-6f76465564-j8dq2 1/1 Running 0 67m 
  5. ​ 
  6. kubectl exec -it mysql-6f76465564-j8dq2 bash 
  7. root@mysql-6f76465564-j8dq2:/usr/local/mysql# mysql -u root -p 
  8. Enter password:  
  9. Welcome to the MySQL monitor. Commands end with ; or g. 
  10. Your MySQL connection id is 422 
  11. Server version: 5.7.4-m14 MySQL Community Server (GPL) 
  12. ​ 
  13. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 
  14. ​ 
  15. Oracle is a registered trademark of Oracle Corporation and/or its 
  16. affiliates. Other names may be trademarks of their respective 
  17. owners. 
  18. ​ 
  19. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 
  20. ​ 
  21. mysql>  
  22. mysql> show databases; 
  23. +--------------------+ 
  24. | Database | 
  25. +--------------------+ 
  26. | information_schema | 
  27. | demo | 
  28. | mysql | 
  29. | performance_schema | 
  30. +--------------------+ 
  31. 4 rows in set (0.00 sec) 
  32. ​ 
  33. mysql> use demo; 
  34. Reading table information for completion of table and column names 
  35. You can turn off this feature to get a quicker startup with -A 
  36. ​ 
  37. Database changed 
  38. mysql> show tables; 
  39. +--------------------+ 
  40. | Tables_in_demo | 
  41. +--------------------+ 
  42. | demo_users | 
  43. | hibernate_sequence | 
  44. +--------------------+ 
  45. 2 rows in set (0.00 sec) 
  46. ​ 
  47. mysql> select * from demo_users; 
  48. +----+---------------------+---------------------+-------------+------+------+ 
  49. | id | birth_day | create_date | email | name | sex | 
  50. +----+---------------------+---------------------+-------------+------+------+ 
  51. | 1 | 2019-03-31 04:03:43 | 2019-03-31 04:03:43 | A1@test.com | A1 | 0 | 
  52. | 2 | 2019-03-31 04:03:43 | 2019-03-31 04:03:43 | B2@test.com | B2 | 1 | 
  53. +----+---------------------+---------------------+-------------+------+------+ 
  54. 2 rows in set (0.00 sec) 

通过mysql命令行我们可以看到刚才的测试数据已经保存到数据库中。

(编辑:晋中站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读