【问题标题】:Configure SMTP for SonarQube on Kubernetes Helm Chart在 Kubernetes Helm Chart 上为 SonarQube 配置 SMTP
【发布时间】:2020-01-26 17:23:24
【问题描述】:

我想在 Kubernetes 上自动部署 SonarQube,因此目标是自动配置所有内容。我成功地为 helm chart 创建了一个values.yaml,用于安装 LDAP 插件并使用我们的 DC 对其进行配置。但是当configuring email settings like SMTP host 时,它们似乎被忽略了。

已经尝试彻底删除图表并重新安装:

helm delete --purge sonarqube-test
helm install stable/sonarqube --namespace sonarqube-test --name sonarqube-test -f values-test.yaml

尽管我设置了例如http.proxyHost 到我们的邮件服务器,部署这些 values.yaml 后 UI 中仍然是空的;

sonarProperties 属性是documented,它似乎可以工作:应用了来自 ldap 等其他属性,因为我可以在更新值后使用 LDAP 登录。

我不确定这是否与 k8s 相关,因为 other said it works generally。我使用kubectl exec进入容器并查看了生成的sonar.properties文件,看起来不错:

$ cat /opt/sonarqube/conf/sonar.properties 
email.from=noreply@mydomain.com
email.fromName=SonarQube Test
email.prefix=[SONARQUBE Test]
email.smtp_host.secured=mymailserver.internal
sonar.security.realm=LDAP
sonar.updatecenter.activate=true
sonar.web.javaOpts=-Xmx2048m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -serversonarqube

还有一些 LDAP 的属性,如绑定用户等,我将其删除。

那么为什么更新图表后没有应用电子邮件设置,甚至在完全删除并重新部署后也不应用?

values.yaml

replicaCount: 1
image:
  tag: 7.9-community

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: true
  hosts:
    - name: sonarqube-test.mycluster.internal
      path: /
  tls:
    - hosts:
      - sonarqube-test.mycluster.internal

persistence:
  enabled: true
  storageClass: nfs-client
  accessMode: ReadWriteOnce
  size: 10Gi

postgresql:
  enabled: true

plugins:
  install: 
    - "https://github.com/SonarSource/sonar-ldap/releases/download/2.2-RC3/sonar-ldap-plugin-2.2.0.601.jar"

sonarProperties:
  sonar.web.javaOpts: "-Xmx2048m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -server"
  sonar.security.realm: LDAP
  ldap.url: "..."
  # More ldap config vars ...
  sonar.updatecenter.activate: true

  email.smtp_host.secured: "mymailserver.internal"
  email.fromName: "SonarQube Test"
  email.from: "noreply@mydomain.com"
  email.prefix: "[SONARQUBE Test]"

resources: 
  limits:
    cpu: 4000m
    memory: 8096Mi
  requests:
    cpu: 500m
    memory: 3096Mi

【问题讨论】:

  • 还有问题吗?你修好了吗?
  • @MaggieO 遗憾的是,我还没有解决方案来自动执行此操作。我目前的解决方法是手动设置它们并记录这些更改。

标签: kubernetes sonarqube properties-file


【解决方案1】:

您已经为 sonarqube 定义了图表并在 value.yaml 文件中配置了tls。请注意,您没有根据声纳队列的定义指定秘密名称,您的 tls 部分应如下所示。请记住,您必须手动在适当的命名空间中创建此密钥。

用于配置 tls 的模板如下所示:

tls: []
# Secrets must be manually created in the namespace.
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

So in your case this section should loks like this:

tls: []
# Secrets must be manually created in the namespace.
- secretName: your-secret-name
hosts:
- sonarqube-test.mycluster.internal

同时在配置 postgresql 依赖项时,您没有为 postgreSQL 指定用户、数据库、密码和端口,您应该这样做,因为您选择使用此数据库而不是 mySQL

这是模板:

database:
type: "postgresql"
## Configuration values for postgresql dependency
## ref: https://github.com/kubernetes/charts/blob/master/stable/postgresql/README.md
postgresql:
# Enable to deploy the PostgreSQL chart
enabled: true
# To use an external PostgreSQL instance, set enabled to false and uncomment
# the line below:
# postgresServer: ""
# To use an external secret for the password for an external PostgreSQL
# instance, set enabled to false and provide the name of the secret on the
# line below:
# postgresPasswordSecret: ""
postgresUser: "sonarUser"
postgresPassword: "sonarPass"
postgresDatabase: "sonarDB"
# Specify the TCP port that PostgreSQL should use
service:
port: 5432

SMTP 失败的最常见原因是出站邮件配置错误。 您必须在 SMTP 配置中引入以下参数:

  • SMTP 主机
  • SMTP 端口
  • SMTP 用户名
  • SMTP 密码
  • SMTP 加密

检查这些参数是否由您的邮件提供商提供。 检查您是否已按照应用程序文档页面中的“配置出站邮件设置”部分进行操作。

在您的情况下,您没有指定密码、用户名和端口。 将以下部分添加到您的 sonar.properities 定义中:

email.smtp_port.secured=port-name
email.smtp_secure_connection.secured=true
email.smtp_username.secured=your-username
email.smtp_password.secured=your-password

接下来的事情: 确保您的云环境允许 SMTP 端口中的流量。

为避免大规模垃圾邮件攻击,一些云不允许 SMTP 流量在其默认端口中。

  • Google Cloud Platform 默认不允许 SMTP 流量 端口 25、465 或 587
  • GoDaddy 还阻止 SMTP 流量。

这是与 SMTP 问题相关的故障排除文档:SMTP-issues。 确保您没有其中之一。

如果有帮助,请告诉我。

【讨论】:

    猜你喜欢
    • 2020-04-01
    • 2022-11-14
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多