goctl kube

Overview

goctl kube can quickly generate kubernetes employment resource files.

Make k8s yaml file for head?Believe you have met: as well.

  • There are many parameters for K8S yaml, you need to write to the edge?
  • What is the number of rollback versions to keep?
  • How to detect successful startup and how do you explore?
  • How to allocate and limit resources?
  • How do I set the timezone?Otherwise, print log is GMT standard time
  • How do I expose services to other service calls?
  • How to configure horizontal scaling-up based on CPU and memory usage rates?

First of all, you need to know about these points of knowledge and secondly to make them clear and easy to understand. Once again, writing is still easy to make!

goctl Kube directive

  1. $ goctl kube --help
  2. Generate kubernetes files
  3. Usage:
  4. goctl kube [command]
  5. Available Commands:
  6. deploy Generate deployment yaml file
  7. Flags:
  8. -h, --help help for kube
  9. Use "goctl kube [command] --help" for more information about a command.

goctl kube currently supports generating employment yaml files.

goctl kube deploy directive

  1. $ goctl kube deploy --help
  2. Generate deployment yaml file
  3. Usage:
  4. goctl kube deploy [flags]
  5. Flags:
  6. --branch string The branch of the remote repo, it does work with --remote
  7. -h, --help help for deploy
  8. --home string The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  9. --image string The docker image of deployment (required)
  10. --imagePullPolicy string Image pull policy. One of Always, Never, IfNotPresent
  11. --limitCpu int The limit cpu to deploy (default 1000)
  12. --limitMem int The limit memory to deploy (default 1024)
  13. --maxReplicas int The max replicas to deploy (default 10)
  14. --minReplicas int The min replicas to deploy (default 3)
  15. --name string The name of deployment (required)
  16. --namespace string The namespace of deployment (required)
  17. --nodePort int The nodePort of the deployment to expose
  18. --o string The output yaml file (required)
  19. --port int The port of the deployment to listen on pod (required)
  20. --remote string The remote git repo of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority
  21. The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
  22. --replicas int The number of replicas to deploy (default 3)
  23. --requestCpu int The request cpu to deploy (default 500)
  24. --requestMem int The request memory to deploy (default 512)
  25. --revisions int The number of revision history to limit (default 5)
  26. --secret string The secret to image pull from registry
  27. --serviceAccount string The ServiceAccount for the deployment
  28. --targetPort int The targetPort of the deployment, default to port
goctl kube - 图1 Parameter fieldgoctl kube - 图2 Parameter Typegoctl kube - 图3 Required?goctl kube - 图4 Default valuegoctl kube - 图5 Parameter Description
branchstringNOEmpty stringRemote template name is used only if remote has value
homestringNO${HOME}/.goctlLocal Template File Directory
imagestringYESEmpty stringImage name
imagePullPolicystringYESEmpty stringImage pull policy, Always: Always pull, Never: Never pull, IfNotPresent: Pull when it does not exist
limitCpuintNO1000cpu resource usage limit
limitMemintNO1024Maximum memory usage
maxReplicasintNO10Maximum number of replicas
minReplicasintNO3Minimum number of replicas
namestringYESEmpty stringdeployment 名称
namespacestringYESEmpty stringk8s Domain Space
nodePortintYES0Service port to be exposed
ostringYESEmpty stringyaml file name
portintYES0Port to listen
remotestringNOEmpty stringRemote template is a git repository address. Priority is higher than home field value when this field is passed
replicasintNO3Number of replicas
requestCpuintNO500cpu limit
requestMemintNO512Memory limit
revisionsintNO1Number of reserved versions, easy to roll back
secretstringNOEmpty stringPull the key of the mirror
serviceAccountstringNOEmpty stringService account
targetPortintNO0Target port

Examples

We use the redis image as an example of how to generate employment yaml files using goctl kube uploy instructions.

  1. $ goctl kube deploy -name redis -namespace adhoc -image redis:6-alpine -o redis.yaml -port 6379
  2. Done.

After executing the above command, redis.yaml files will be generated in the current directory, following:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: redis
  5. namespace: adhoc
  6. labels:
  7. app: redis
  8. spec:
  9. replicas: 3
  10. revisionHistoryLimit: 5
  11. selector:
  12. matchLabels:
  13. app: redis
  14. template:
  15. metadata:
  16. labels:
  17. app: redis
  18. spec:
  19. containers:
  20. - name: redis
  21. image: redis:6-alpine
  22. ports:
  23. - containerPort: 6379
  24. readinessProbe:
  25. tcpSocket:
  26. port: 6379
  27. initialDelaySeconds: 5
  28. periodSeconds: 10
  29. livenessProbe:
  30. tcpSocket:
  31. port: 6379
  32. initialDelaySeconds: 15
  33. periodSeconds: 20
  34. resources:
  35. requests:
  36. cpu: 500m
  37. memory: 512Mi
  38. limits:
  39. cpu: 1000m
  40. memory: 1024Mi
  41. volumeMounts:
  42. - name: timezone
  43. mountPath: /etc/localtime
  44. volumes:
  45. - name: timezone
  46. hostPath:
  47. path: /usr/share/zoneinfo/Asia/Shanghai
  48. ---
  49. apiVersion: v1
  50. kind: Service
  51. metadata:
  52. name: redis-svc
  53. namespace: adhoc
  54. spec:
  55. ports:
  56. - port: 6379
  57. targetPort: 6379
  58. selector:
  59. app: redis
  60. ---
  61. apiVersion: autoscaling/v2beta1
  62. kind: HorizontalPodAutoscaler
  63. metadata:
  64. name: redis-hpa-c
  65. namespace: adhoc
  66. labels:
  67. app: redis-hpa-c
  68. spec:
  69. scaleTargetRef:
  70. apiVersion: apps/v1
  71. kind: Deployment
  72. name: redis
  73. minReplicas: 3
  74. maxReplicas: 10
  75. metrics:
  76. - type: Resource
  77. resource:
  78. name: cpu
  79. targetAverageUtilization: 80
  80. ---
  81. apiVersion: autoscaling/v2beta1
  82. kind: HorizontalPodAutoscaler
  83. metadata:
  84. name: redis-hpa-m
  85. namespace: adhoc
  86. labels:
  87. app: redis-hpa-m
  88. spec:
  89. scaleTargetRef:
  90. apiVersion: apps/v1
  91. kind: Deployment
  92. name: redis
  93. minReplicas: 3
  94. maxReplicas: 10
  95. metrics:
  96. - type: Resource
  97. resource:
  98. name: memory
  99. targetAverageUtilization: 80