项目作者: DevineLiu

项目描述 :
用于生成简单的k8s yaml模版
高级语言: Python
项目地址: git://github.com/DevineLiu/liquid_k8s_yaml_generator.git
创建时间: 2019-08-22T02:58:13Z
项目社区:https://github.com/DevineLiu/liquid_k8s_yaml_generator

开源协议:MIT License

下载


liquid_k8s_yaml_generator

用于生成简单的k8s yaml配置文件

install

  1. pip install git+https://github.com/DevineLiu/liquid_k8s_yaml_generator.git@master

usage

  1. import liquid_k8s_yaml_generator
  2. yaml_fb = liquid_k8s_yaml_generator.template.render(
  3. image_name="test-demo", #被应用于作为服务、istio vs、应用名、sls 的名字的生成 禁止下划线
  4. replicas=2,
  5. remote_image_name="ubuntu:latest" , # 镜像地址
  6. port = 80, #应用开放的端口
  7. env_items = {"KEY":"vaule"}, #环境变量
  8. log_path = "/log/*log" #sls 采集日志的地址
  9. )
  10. print(yaml_fb)

stdout:

  1. apiVersion: apps/v1beta2
  2. kind: Deployment
  3. metadata:
  4. name: test-demo
  5. namespace: default
  6. spec:
  7. replicas: 2
  8. selector:
  9. matchLabels:
  10. app: test-demo
  11. template:
  12. metadata:
  13. labels:
  14. app: test-demo
  15. spec:
  16. containers:
  17. - name: test-demo
  18. image: 'ubuntu:latest'
  19. env:
  20. ######### 配置 环境变量 ###########
  21. - name: KEY
  22. value: vaule
  23. - name: aliyun_logs_test-demo-stdout
  24. value: stdout
  25. - name: aliyun_logs_test-demo-log
  26. value: /log/*log
  27. ports:
  28. - containerPort: 80
  29. ###############################
  30. ---
  31. apiVersion: v1
  32. kind: Service
  33. metadata:
  34. name: test-demo-svc
  35. labels:
  36. app: test-demo
  37. service: test-demo
  38. spec:
  39. ports:
  40. - port: 80
  41. name: test-demo-svc
  42. selector:
  43. app: test-demo
  44. type: LoadBalancer
  45. ---
  46. apiVersion: networking.istio.io/v1alpha3
  47. kind: VirtualService
  48. metadata:
  49. name: test-demo-vs
  50. namespace: default
  51. spec:
  52. hosts:
  53. - test-demo-vs-svc
  54. http:
  55. - route:
  56. - destination:
  57. host: test-demo-svc
  58. subset: test-demo-svc
  59. ---
  60. apiVersion: v1
  61. kind: Service
  62. metadata:
  63. name: test-demo-vs-svc
  64. labels:
  65. app: test-demo-vs
  66. service: test-demo-vs
  67. spec:
  68. ports:
  69. - port: 80
  70. name: test-demo-vs-svc
  71. targetPort: 80
  72. selector:
  73. app: test-demo
  74. type: LoadBalancer