How to deploy nginx with ftp?

10/17/2019

Recently I start to stady Kubernetes. Now I know how to deploy nginx in pod with default options, and I know how deply nginx with custom nginx.conf with configmap. Now I have a question if I want to use nginx with ftp. Ftp need to have access in directory where nginx.conf. It is possible ? Maybe someone know simple example ?

-- noute
docker
ftp
kubernetes
linux

1 Answer

10/17/2019

You could have your ftp container as a sidecar for the nginx main container and share the volume between the containers:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: <your nginx image>
        ports:
        - name: http
          containerPort: 80
        volumeMounts:
        - name: config
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
      - name: ftp
        image: <your ftp image>
        ports:
        - name: ftp
          containerPort: 21
        volumeMounts:
        - name: config
          readOnly: true
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
      volumes:
      - name: config
        configMap:
          name: nginx-config

and the service expose both ports

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-ftp
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    targetPort: 80
  - name: ftp
    port: 21
    targetPort: 21
-- Pedreiro
Source: StackOverflow