我有一个使用build.properties的Maven项目,该项目在构建时会变成WEB-INF文件夹中的projectname.properties。
此文件包含数据库连接凭据,因此我想使用configMap,这样就不必将数据库密码提交给git。
当我在部署中将configMap作为文件挂载时,似乎不喜欢它。
我的deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pyx-tr-staging
labels:
app: pyx-tr-staging
namespace: pyx-tr
spec:
replicas: 1
selector:
matchLabels:
app: pyx-tr-staging
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 33%
template:
metadata:
labels:
app: pyx-tr-staging
spec:
containers:
- name: pyx-tr-staging
image: registry.gitlab.com/lb-dev/projects/pyx/pyx-tr:<VERSION>
ports:
- containerPort: 8080
volumeMounts:
- name: config-volume
mountPath: /propfiles/
lifecycle:
postStart:
exec:
command: ["cp", "/propfiles/pyx.properties", "/usr/local/tomcat/webapps/ROOT/WEB-INF/"]
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 2
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 2
periodSeconds: 2
imagePullSecrets:
- name: regcred
volumes:
- name: config-volume
configMap:
name: pyx-tr-config
我的Configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: pyx-tr-config
namespace: pyx-tr
data:
pyx.properties: |
pyx.cookie_domain=.localhost
pyx.max_users=100
pyx.max_games=25
pyx.include_inactive_cardsets=false
pyx.broadcast_connects_and_disconnects=true
pyx.global_chat_enabled=true
pyx.game_chat_enabled=true
# allow fill-in-the-blank cards at all. Limits are set via constants in GameOptions.
pyx.allow_blank_cards=true
# allow identification codes to be used without HTTPS
pyx.insecure_id_allowed=true
# set this to some secure random value, and never change it, unless you want to break all codes
pyx.id_code_salt=
# comma-separated listed of IP addresses (v4 or v6) from which users are considered admins.
# IPv6 addresses must be fully spelt out without omitting groups of 0s with ::
pyx.admin_addrs=127.0.0.1,0:0:0:0:0:0:0:1
# comma-separated list of strings banned from appearing in nicks.
pyx.banned_nicks=xyzzy
# The name of a class that implements net.socialgamer.cah.util.ChatFilter.ShadowBannedStringProvider
# which will then be called to get the shadowbanned strings.
# Ideally we'd just have the list of strings here, but providing unicode characters directly gets
# mangled during the build process, and for some reason unicode escapes were not being loaded
# properly at runtime.
# If this is blank, it is ignored and no strings will cause such filtering to occur.
pyx.shadowban_strings_provider=
# Settings for global chat protection. Some of these do not apply to game chats.
# Ratio of 'basic' characters to length of message. Basic characters are defined by
# Character.isJavaIdentifierPart, which stipulates:
# -it is a letter
# -it is a currency symbol (such as '$')
# -it is a connecting punctuation character (such as '_')
# -it is a digit
# -it is a numeric letter (such as a Roman numeral character)
# -it is a combining mark
# -it is a non-spacing mark
# -isIdentifierIgnorable(codePoint) returns true for the character
pyx.global.basic_ratio=.5
# A message must have at least this many characters for that ratio to apply.
pyx.global.basic_min_len=10
# Message longer than min_len characters cannot have more than ratio of CAPS CHARACTERS
pyx.global.capslock_min_len=50
pyx.global.capslock_ratio=.5
# messages longer than min_len characters require at least min_count spaces between words
pyx.global.spaces_min_len=50
pyx.global.spaces_min_count=4
# this many messages to global chat in that many seconds is considered chatting too fast.
pyx.global.flood_count=3
# seconds
pyx.global.flood_time=25
# Messages with more than repeated_words_min_count words must have at least
# repeated_words_unique_ratio unique words in them.
pyx.global.repeated_words_min_count=10
pyx.global.repeated_words_unique_ratio=.5
# Settings for game chat protection. If it isn't listed here, it isn't supported.
# same but for game chats
pyx.game.flood_count=5
# seconds
pyx.game.flood_time=30
# for production use, use postgres
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.driver_class=org.postgresql.Driver
hibernate.url=jdbc:postgresql://postgres/db
# for local use, you can also use sqlite
# hibernate.dialect=net.socialgamer.cah.hibernate.SqliteDialect
# hibernate.driver_class=org.sqlite.JDBC
# hibernate.url=jdbc:sqlite:pyx.sqlite
# these likely need specified even with sqlite, even though they don't matter
hibernate.username=pyx
hibernate.password=REDACTED
# debugging information
hibernate.sql.show=false
hibernate.sql.format=false
当我将其部署到我的Kubernetes集群时,容器永不启动,因为它没有通过活动性和就绪性探测,因此它会继续重新启动容器。
如果我只保留示例文件,它将运行正常
我得到的错误是生命周期postStart返回此
Exec lifecycle hook ([cp /propfiles/pyx.properties /usr/local/tomcat/webapps/ROOT/WEB-INF/]) for Container "pyx-tr-staging" in Pod "pyx-tr-staging-67b47c75cc-nlvzg_pyx-tr(724820f1-9980-11e9-b0bb-aa44c6500e0e)" failed - error: command 'cp /propfiles/pyx.properties /usr/local/tomcat/webapps/ROOT/WEB-INF/' exited with 1: cp: cannot create regular file '/usr/local/tomcat/webapps/ROOT/WEB-INF/': No such file or directory , message: "cp: cannot create regular file '/usr/local/tomcat/webapps/ROOT/WEB-INF/': No such file or directory\n"