콘텐츠로 이동

goctl Kubernetes

  • How should CPU과 메모리 requests/limits be set?
  • How should 서비스 be exposed 로 other callers?
Terminal window
$ goctl kube --help
Generate kubernetes files
Usage:
goctl kube [command]
Available 명령s:
deploy Generate deployment yaml file
Flags:
-h, --help help for kube
Use "goctl kube [command] --help" for more information about a command.

goctl kube currently 지원합니다 generating 배포 YAML 파일.

Terminal window
$ goctl kube deploy --help
Generate deployment yaml file
Usage:
goctl kube deploy [flags]
Flags:
--branch string The branch of the remote repo, it does work with --remote
-h, --help help for deploy
--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
--image string The docker image of deployment (required)
--imagePullPolicy string Image pull policy. One of Always, Never, IfNotPresent
--limitCpu int The limit cpu to deploy (default 1000)
--limitMem int The limit memory to deploy (default 1024)
--maxReplicas int The max replicas to deploy (default 10)
--minReplicas int The min replicas to deploy (default 3)
--name string The name of deployment (required)
--namespace string The namespace of deployment (required)
--nodePort int The nodePort of the deployment to expose
--o string The output yaml file (required)
--port int The port of the deployment to listen on pod (required)
--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
The git repo directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure
--replicas int The number of replicas to deploy (default 3)
--requestCpu int The request cpu to deploy (default 500)
--requestMem int The request memory to deploy (default 512)
--revisions int The number of revision history to limit (default 5)
--secret string The secret to image pull from registry
--serviceAccount string The ServiceAccount for the deployment
--targetPort int The targetPort of the deployment, default to port
매개변수 필드 매개변수 타입 필수? 기본값 value 매개변수 설명
branchstring없음Empty string원격 템플릿 name is 사용됨 만 경우 remote has value
homestring없음${HOME}/.goctl로컬 템플릿 파일 디렉터리
imagestringYESEmpty stringImage name
imagePullPolicystringYESEmpty stringImage Pull policy, Always: Always Pull, Never: Never Pull, IfNotPresent: Pull 때 it does 아님 exist
limitCpuint없음1000cpu resource usage 제한
limitMemint없음1024Maximum 메모리 usage
maxReplicasint없음10Maximum number 의 replicas
minReplicasint없음3Minimum number 의 replicas
namestringYESEmpty stringDeployment name
namespacestringYESEmpty stringKubernetes namespace
nodePortintYES0Service 포트 로 be exposed
ostringYESEmpty stringyaml 파일 name
포트intYES0포트 로 listen
원격string없음Empty string해당 항목의 동작과 사용법을 설명합니다.
replicasint없음3Number 의 replicas
requestCpuint없음500cpu 제한
requestMemint없음512메모리 제한
revisionsint없음1Number 의 reserved 버전, easy 로 roll back
secretstring없음Empty string레지스트리 image Pull secret
serviceAccountstring없음Empty stringService account
targetPortint없음0Target 포트

사용하여 Redis image 로서 예제, here은 how 로 생성 배포 YAML 파일 사용하여 goctl kube deploy입니다.

Terminal window
$ goctl kube deploy -name redis -namespace adhoc -image redis:6-alpine -o redis.yaml -port 6379
Done.
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: adhoc
labels:
app: redis
spec:
replicas: 3
revisionHistoryLimit: 5
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:6-alpine
ports:
- containerPort: 6379
readinessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 6379
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: redis-svc
namespace: adhoc
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: redis-hpa-c
namespace: adhoc
labels:
app: redis-hpa-c
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: redis
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 80
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: redis-hpa-m
namespace: adhoc
labels:
app: redis-hpa-m
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: redis
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: memory
targetAverageUtilization: 80