我使用 kustomize 作为独立的二进制文件(随 Homebrew 一起安装),并具有以下base/kustomization.yaml文件:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
app: myservice
app.kubernetes.io/name: myservice
service: myservicename
vendor: mycompany
app.kubernetes.io/version: "0.1.0"
namePrefix: myservice-
namespace: mynamespace
commonAnnotations:
supportMail: support@sagich.net
resources:
- pre-install-job.yaml
- cronjob.yaml
- service.yaml
- api.yaml
- worker.yaml
configMapGenerator:
- files:
- env.properties
name: configmap
secretGenerator:
- envs:
- env.properties
name: env-file-secret
env.properties文件如下所示:
APP_NAME="vendor-service-whatever"
APP_ENV="production"
APP_KEY="base64:onKQb...LtU="
APP_DEBUG="false"
APP_URL="https://myamazingsite.com"
LOG_CHANNEL="stderr"
DB_CONNECTION="mysql"
DB_HOST="mariadb-slave"
DB_DATABASE="incredibledb"
在我的pre-install-job.yaml配置中,我声明了一个这样的容器:
containers:
- name: "pre-install-job"
image: "registry.myamazingdomain.com/vendor/whatever/service:latest"
imagePullPolicy: "Always"
args:
- /bin/bash
- -c
- php artisan migrate --force -v;
envFrom:
- configMapRef:
name: "configmap"
问题:环境变量在 pod/container 中不可用。我还尝试将 configmap 作为 .env 文件安装在容器中,但也没有成功。也许有人可以指出我正确的方向。
产生的错误是:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection denied (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations and table_type = 'BASE TABLE')
因为使用默认值而不是环境变量中定义的值。