0

I'm struggling to create two JSON config files in the main application directory (/publish) while leaving all other files in that directory intact. I tried the following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: url_to_image
        ports:
        - containerPort: 1234
        volumeMounts:
        - name: config-files
          mountPath: "/publish"
      volumes:
      - name: config-files
        configMap:
          name: myapp
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  ports:
    - port: 80
      targetPort: 1234
      protocol: TCP
  type: NodePort
  selector:
    app: myapp
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: myapp
  labels:
    app: myapp
data:
  appsettings.json: |
    { some JSON }
  sharedsettings.json: |
    { more JSON }

Two config files (appsettings.json and sharedsettings.json) are correctly created but unfortunately all other files in /publish are deleted in the process.

What would be the best approach?

0

Ok, found a solution but it's not very elegant. Any better solutions out there?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: url_to_image
        ports:
        - containerPort: 1234
        volumeMounts:
        - name: appsettings
          mountPath: "/publish/appsettings.json"
          subPath: whatever
        volumeMounts:
        - name: sharedsettings
          mountPath: "/publish/sharedsettings.json"
          subPath: whatever
      volumes:
      - name: appsettings
        configMap:
          name: myapp
          items:
          - key: appsettings.json
            path: whatever
      - name: sharedsettings
        configMap:
          name: myapp
          items:
          - key: sharedsettings.json
            path: whatever
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  ports:
    - port: 80
      targetPort: 1234
      protocol: TCP
  type: NodePort
  selector:
    app: myapp
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: myapp
  labels:
    app: myapp
data:
  appsettings.json: |
    { some JSON }
  sharedsettings.json: |
    { more JSON }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.