feat: support targetPort option in goctl kube (#2378)
This commit is contained in:
@@ -16,6 +16,7 @@ var (
|
|||||||
varIntRevisions int
|
varIntRevisions int
|
||||||
varIntPort int
|
varIntPort int
|
||||||
varIntNodePort int
|
varIntNodePort int
|
||||||
|
varIntTargetPort int
|
||||||
varIntMinReplicas int
|
varIntMinReplicas int
|
||||||
varIntMaxReplicas int
|
varIntMaxReplicas int
|
||||||
varStringHome string
|
varStringHome string
|
||||||
@@ -51,6 +52,7 @@ func init() {
|
|||||||
deployCmd.Flags().IntVar(&varIntRevisions, "revisions", 5, "The number of revision history to limit")
|
deployCmd.Flags().IntVar(&varIntRevisions, "revisions", 5, "The number of revision history to limit")
|
||||||
deployCmd.Flags().IntVar(&varIntPort, "port", 0, "The port of the deployment to listen on pod (required)")
|
deployCmd.Flags().IntVar(&varIntPort, "port", 0, "The port of the deployment to listen on pod (required)")
|
||||||
deployCmd.Flags().IntVar(&varIntNodePort, "nodePort", 0, "The nodePort of the deployment to expose")
|
deployCmd.Flags().IntVar(&varIntNodePort, "nodePort", 0, "The nodePort of the deployment to expose")
|
||||||
|
deployCmd.Flags().IntVar(&varIntTargetPort, "targetPort", 0, "The targetPort of the deployment, default to port")
|
||||||
deployCmd.Flags().IntVar(&varIntMinReplicas, "minReplicas", 3, "The min replicas to deploy")
|
deployCmd.Flags().IntVar(&varIntMinReplicas, "minReplicas", 3, "The min replicas to deploy")
|
||||||
deployCmd.Flags().IntVar(&varIntMaxReplicas, "maxReplicas", 10, "The max replicas to deploy")
|
deployCmd.Flags().IntVar(&varIntMaxReplicas, "maxReplicas", 10, "The max replicas to deploy")
|
||||||
deployCmd.Flags().StringVar(&varStringImagePullPolicy, "imagePullPolicy", "", "Image pull policy. One of Always, Never, IfNotPresent")
|
deployCmd.Flags().StringVar(&varStringImagePullPolicy, "imagePullPolicy", "", "Image pull policy. One of Always, Never, IfNotPresent")
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ metadata:
|
|||||||
namespace: {{.Namespace}}
|
namespace: {{.Namespace}}
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
{{if .UseNodePort}}- nodePort: {{.NodePort}}
|
{{if .UseNodePort}}- nodePort: {{.NodePort}}
|
||||||
port: {{.Port}}
|
port: {{.Port}}
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
targetPort: {{.Port}}
|
targetPort: {{.TargetPort}}
|
||||||
type: NodePort{{else}}- port: {{.Port}}{{end}}
|
type: NodePort{{else}}- port: {{.Port}}
|
||||||
|
targetPort: {{.TargetPort}}{{end}}
|
||||||
selector:
|
selector:
|
||||||
app: {{.Name}}
|
app: {{.Name}}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type Deployment struct {
|
|||||||
Replicas int
|
Replicas int
|
||||||
Revisions int
|
Revisions int
|
||||||
Port int
|
Port int
|
||||||
|
TargetPort int
|
||||||
NodePort int
|
NodePort int
|
||||||
UseNodePort bool
|
UseNodePort bool
|
||||||
RequestCpu int
|
RequestCpu int
|
||||||
@@ -81,6 +82,10 @@ func deploymentCommand(_ *cobra.Command, _ []string) error {
|
|||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
|
if varIntTargetPort == 0 {
|
||||||
|
varIntTargetPort = varIntPort
|
||||||
|
}
|
||||||
|
|
||||||
t := template.Must(template.New("deploymentTemplate").Parse(text))
|
t := template.Must(template.New("deploymentTemplate").Parse(text))
|
||||||
err = t.Execute(out, Deployment{
|
err = t.Execute(out, Deployment{
|
||||||
Name: varStringName,
|
Name: varStringName,
|
||||||
@@ -90,6 +95,7 @@ func deploymentCommand(_ *cobra.Command, _ []string) error {
|
|||||||
Replicas: varIntReplicas,
|
Replicas: varIntReplicas,
|
||||||
Revisions: varIntRevisions,
|
Revisions: varIntRevisions,
|
||||||
Port: varIntPort,
|
Port: varIntPort,
|
||||||
|
TargetPort: varIntTargetPort,
|
||||||
NodePort: nodePort,
|
NodePort: nodePort,
|
||||||
UseNodePort: nodePort > 0,
|
UseNodePort: nodePort > 0,
|
||||||
RequestCpu: varIntRequestCpu,
|
RequestCpu: varIntRequestCpu,
|
||||||
|
|||||||
108
tools/goctl/tproxy.yaml
Normal file
108
tools/goctl/tproxy.yaml
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: tproxy
|
||||||
|
namespace: adhoc
|
||||||
|
labels:
|
||||||
|
app: tproxy
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
revisionHistoryLimit: 5
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: tproxy
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: tproxy
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: tproxy
|
||||||
|
image: tproxy:v1
|
||||||
|
ports:
|
||||||
|
- containerPort: 8888
|
||||||
|
readinessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: 8888
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 10
|
||||||
|
livenessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: 8888
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 20
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 500m
|
||||||
|
memory: 512Mi
|
||||||
|
limits:
|
||||||
|
cpu: 1000m
|
||||||
|
memory: 1024Mi
|
||||||
|
volumeMounts:
|
||||||
|
- name: timezone
|
||||||
|
mountPath: /etc/localtime
|
||||||
|
volumes:
|
||||||
|
- name: timezone
|
||||||
|
hostPath:
|
||||||
|
path: /usr/share/zoneinfo/Asia/Shanghai
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: tproxy-svc
|
||||||
|
namespace: adhoc
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- nodePort: 30001
|
||||||
|
port: 8888
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8888
|
||||||
|
type: NodePort
|
||||||
|
selector:
|
||||||
|
app: tproxy
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: autoscaling/v2beta1
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: tproxy-hpa-c
|
||||||
|
namespace: adhoc
|
||||||
|
labels:
|
||||||
|
app: tproxy-hpa-c
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: tproxy
|
||||||
|
minReplicas: 3
|
||||||
|
maxReplicas: 10
|
||||||
|
metrics:
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: cpu
|
||||||
|
targetAverageUtilization: 80
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
apiVersion: autoscaling/v2beta1
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
metadata:
|
||||||
|
name: tproxy-hpa-m
|
||||||
|
namespace: adhoc
|
||||||
|
labels:
|
||||||
|
app: tproxy-hpa-m
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: tproxy
|
||||||
|
minReplicas: 3
|
||||||
|
maxReplicas: 10
|
||||||
|
metrics:
|
||||||
|
- type: Resource
|
||||||
|
resource:
|
||||||
|
name: memory
|
||||||
|
targetAverageUtilization: 80
|
||||||
Reference in New Issue
Block a user