我正在尝试使用云代理和Sidecar容器模式从Kubernetes集群连接CloudSQL。代理和Cloudsql容器都在同一个容器中,它们都在成功运行。
但是,cloudproxy容器始终处于“运行”状态,作业没有处于已完成状态。正因为如此,其他工作才不会被触发。
我能知道最好的解决办法吗?

也请找到我的.yml模板。
restartPolicy: Never
securityContext:
{{- toYaml .Values.mysqlSetupJob.podSecurityContext | nindent 8 }}
containers:
- name: mysql-setup-job
image: "{{ .Values.mysqlSetupJob.image.repository }}:{{ .Values.mysqlSetupJob.image.tag }}"
imagePullPolicy: {{ .Values.mysqlSetupJob.imagePullPolicy | default "IfNotPresent" }}
env:
- name: MYSQL_USERNAME
value: {{ .Values.global.sql.datasource.username | quote }}
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: "{{ .Values.global.sql.datasource.password.secretRef }}"
key: "{{ .Values.global.sql.datasource.password.secretKey }}"
- name: MYSQL_HOST
value: {{ .Values.global.sql.datasource.hostForMysqlClient | quote }}
- name: MYSQL_PORT
value: {{ .Values.global.sql.datasource.port | quote }}
{{- with .Values.mysqlSetupJob.extraEnvs }}
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- toYaml .Values.mysqlSetupJob.securityContext | nindent 12 }}
volumeMounts:
{{- with .Values.mysqlSetupJob.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 300m
memory: 256Mi
{{- if .Values.cloudsqlProxy.required }}
- name: cloud-sql-proxy
image: {{ .Values.cloudsqlProxy.image }}
command:
- "/cloud_sql_proxy"
- "-instances={{ .Values.cloudsqlProxy.instance_connection_name }}=tcp:{{ .Values.cloudsqlProxy.port }}"
{{- if .Values.gcp.serviceAccount.secretName }}
- "-credential_file={{ .Values.gcp.serviceAccount.mountPoint }}/{{ .Values.gcp.serviceAccount.secretKey }}"
{{- end }}
securityContext:
runAsNonRoot: true
resources:
{{- toYaml .Values.cloudsqlProxy.resources | nindent 12 }}
{{- if .Values.gcp.serviceAccount.secretName }}
volumeMounts:
- name: serviceaccount
mountPath: {{ .Values.gcp.serviceAccount.mountPoint }}
readOnly: true
{{- end }}
{{- end }}
{{- with .Values.mysqlSetupJob.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.mysqlSetupJob.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.mysqlSetupJob.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}{{-结束-}
发布于 2022-10-25 09:48:42
这个问题解决了。您可以做的是在作业之外运行代理。这样,您就不能再使用localhost连接到它了,但是您仍然可以在内部公开代理集群,并使用它的Kubernetes DNS名称来调用它。
发布于 2022-10-24 15:31:09
迁移完成后,需要关闭CLoud SQL代理。我们通常建议人们在term_timeout标志和timeout一起使用,以确保代理在所有连接都关闭时关闭,如下所示:
timeout 60 /cloud_sql_proxy --instances=<...> --term_timeout=3600sFYI:这里有一个支持关机端点的特性请求:https://github.com/GoogleCloudPlatform/cloud-sql-proxy/issues/828。
https://stackoverflow.com/questions/74144253
复制相似问题