设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2019-11-08 01:11 所属栏目:115 来源:云计算AND容器技术
导读:通过restful api向数据库写入测试数据 curl-XPOSThttp://10.0.0.10:8001/api/v1/namespaces/default/services/demo/proxy/service/v1/user-Haccept:application/json-HContent-Type:application/json-d{\birthDay\:

通过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命令行我们可以看到刚才的测试数据已经保存到数据库中。

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读