gpt4 book ai didi

spring-boot - Spring Boot +谷歌kubernetes +谷歌SQL云无法正常工作

转载 作者:行者123 更新时间:2023-12-02 12:08:15 25 4
gpt4 key购买 nike

我正在尝试在Google kubernetes(Google Container Engine)中推送Spring Boot应用程序。

我已经执行了下面链接中给出的所有步骤。

https://codelabs.developers.google.com/codelabs/cloud-springboot-kubernetes/index.html?index=..%2F..%2Findex#0

当我尝试在无法访问的浏览器中执行步骤9 http://:8080时。

是的,我有外部IP地址。

我可以ping该IP地址

让我知道是否需要其他信息。

在无法连接数据库的日志记录中

错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

最佳答案

我希望您已经在Google容器引擎中创建了集群

遵循此链接中给出的前5个步骤

https://cloud.google.com/sql/docs/mysql/connect-container-engine

更改应用程序中的数据库配置
hostname: 127.0.0.1
port: 3306 or your mysql port
username: proxyuser

应与链接步骤-3相同

  • mvn软件包-Dmaven.test.skip = true
  • 创建名称为“Dockerfile”及以下内容的文件
    FROM openjdk:8
    COPY target/SpringBootWithDB-0.0.1-SNAPSHOT.jar /app.jar
    EXPOSE 8080/tcp
    ENTRYPOINT ["java", "-jar", "/app.jar"]
  • docker build -t gcr.io//springbootdb-java:v1。
  • docker运行-ti --rm -p 8080:8080 gcr.io//springbootdb-java:v1
  • gcloud docker-推送gcr.io//springbootdb-java:v1

    遵循链接中给出的第六步,并创建yaml文件
  • kubectl创建-f cloudsql_deployment.yaml

    运行kubectl获取部署并复制部署名称
  • kubectl公开部署--type = LoadBalancer


  • 我的Yaml文件
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: conversationally
    spec:
    replicas: 1
    template:
    metadata:
    labels:
    app: conversationally
    spec:
    containers:
    - image: gcr.io/<project ID>/springbootdb-java:v1
    name: web
    env:
    - name: DB_HOST
    # Connect to the SQL proxy over the local network on a fixed port.
    # Change the [PORT] to the port number used by your database
    # (e.g. 3306).
    value: 127.0.0.1:3306
    # These secrets are required to start the pod.
    # [START cloudsql_secrets]
    - name: DB_PASSWORD
    valueFrom:
    secretKeyRef:
    name: cloudsql-db-credentials
    key: password
    - name: DB_USER
    valueFrom:
    secretKeyRef:
    name: cloudsql-db-credentials
    key: username
    # [END cloudsql_secrets]
    ports:
    - containerPort: 8080
    name: conv-cluster
    # Change [INSTANCE_CONNECTION_NAME] here to include your GCP
    # project, the region of your Cloud SQL instance and the name
    # of your Cloud SQL instance. The format is
    # $PROJECT:$REGION:$INSTANCE
    # Insert the port number used by your database.
    # [START proxy_container]
    - image: gcr.io/cloudsql-docker/gce-proxy:1.09
    name: cloudsql-proxy
    command: ["/cloud_sql_proxy", "--dir=/cloudsql",
    "-instances=<instance name>=tcp:3306",
    "-credential_file=/secrets/cloudsql/credentials.json"]
    volumeMounts:
    - name: cloudsql-instance-credentials
    mountPath: /secrets/cloudsql
    readOnly: true
    - name: ssl-certs
    mountPath: /etc/ssl/certs
    - name: cloudsql
    mountPath: /cloudsql
    # [END proxy_container]
    # [START volumes]
    volumes:
    - name: cloudsql-instance-credentials
    secret:
    secretName: cloudsql-instance-credentials
    - name: ssl-certs
    hostPath:
    path: /etc/ssl/certs
    - name: cloudsql
    emptyDir:
    # [END volumes]

    ===========

    关于spring-boot - Spring Boot +谷歌kubernetes +谷歌SQL云无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45752676/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com