例:
一、configmap
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
apiVersion: v1 kind: ConfigMap metadata: name: maven-configmap namespace: devops data: settings.xml: |- <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> <localRepository>/usr/local/apache-maven-3.8.6/maven-repertory</localRepository> <pluginGroups> <pluginGroup>com.spotify</pluginGroup> </pluginGroups> <proxies> </proxies> <servers> <server> <id>maven-public</id> <username>admin</username> <password>111111</password> </server> <server> <id>releases</id> <username>admin</username> <password>111111</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>111111</password> </server> </servers> <mirrors> <mirror> <id>maven-public</id> <name>maven-public</name> <mirrorOf>*</mirrorOf> <url>http://192.168.0.10:8081/repository/maven-public/</url> </mirror> </mirrors> <profiles> </profiles> </settings> |
二、secret
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
apiVersion: v1 kind: Secret metadata: name: maven-config namespace: devops type: Opaque stringData: settings.xml: |- <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> <localRepository>/usr/local/apache-maven-3.8.6/maven-repertory</localRepository> <pluginGroups> <pluginGroup>com.spotify</pluginGroup> </pluginGroups> <proxies> </proxies> <servers> <server> <id>maven-public</id> <username>admin</username> <password>111111</password> </server> <server> <id>releases</id> <username>admin</username> <password>111111</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>111111</password> </server> </servers> <mirrors> <mirror> <id>maven-public</id> <name>maven-public</name> <mirrorOf>*</mirrorOf> <url>http://192.168.0.10:8081/repository/maven-public/</url> </mirror> </mirrors> <profiles> </profiles> </settings> |
三、挂载secret
1 2 3 4 5 6 7 |
在Linux中,将目录A挂载到目录B,则目录B原有的文件都会被目录A下的文件覆盖。 那么在k8s中,如何将configmap挂载到容器中某个目录的文件中呢?答案是使用subPath subPath的使用方法一共有两种: 1. 同一个pod中多容器挂载同一个卷时提供隔离 2. 将configMap和secret作为文件挂载到容器中而不覆盖挂载目录下的文件 |
1 2 3 4 |
volumeMounts: - name: volume-d3gekc mountPath: /usr/local/apache-maven-3.8.6/conf/settings.xml subPath: settings.xml #如果没有subPath,则/usr/local/apache-maven-3.8.6/conf/settings.xml将被当成一个目录,根据Linux挂载的概念,该目录下的所有文件会被覆盖. |
例2:
1 2 3 4 5 |
containers: - volumeMounts: - name: demo-config mountPath: /etc/ssl.key subPath: ssl.key #如果没有subPath,则/etc/ssl.key将被当成一个目录,根据Linux挂载的概念,该目录下的所有文件会被覆盖 |
- 本文固定链接: https://www.yoyoask.com/?p=9733
- 转载请注明: shooter 于 SHOOTER 发表