Now I read this config in kubernetes:
containers:
- name: canal-admin-stable
image: 'dolphinjiang/canal-admin:v1.1.5'
ports:
- name: http
containerPort: 8089
protocol: TCP
resources:
limits:
cpu: '2'
memory: 2Gi
requests:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: admin-conf
mountPath: /home/canal/conf/application.yml
subPath: application.yml
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
the volumne mount path(/home/canal/conf/application.yml) already file full path, I think kubernetes only overwrite the file application.yml, why still specify subPath application.yml? Why not write like this:
volumeMounts:
- name: admin-conf
mountPath: /home/canal/conf/
subPath: application.yml
I was using init-containers to pass a config file to the main container and discovered the use behind the mountPath and subPath as it was confusing to me too at first. The mountPath is always the destination inside the Pod a volume gets mounted to. However, I discovered that if your mountPath has other config files in it, then that directory will be overwritten and all that exists will be your file that you mounted.
I only needed to mount part of the volume, such as a single file in a volume, so I used subPath to specify the part to be mounted within the mountPath.
Sometimes using just a mountPath is fine, but I had to also use a subPath to preserve the other config files in the directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With