SocketCluster / SocketCluster/socketcluster

Kubernetes - Use initContainer instead of another container as source volume

Open
#464 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
6.2k
Forks
318
PR merge metrics
No merged PRs in 30d

Description

It's better doing it that way because it's not necessary to wait for the files to become available (as seen here: https://github.com/SocketCluster/socketcluster/blob/5226c2a/sample/dockerwait.js).

Example of how it would work:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-project-scc
spec:
  replicas: 2
  revisionHistoryLimit: 2
  template:
    metadata:
      labels:
        app: my-project-scc
    spec:
      initContainers:
        - name: src-container
          image: myuser/sourceimage
          command:
            - cp
            - '-a'
            - /usr/src/.
            - /usr/dest/
          volumeMounts:
            - mountPath: /usr/dest
              name: src-volume
          resources:
            limits:
              cpu: 10m
              memory: 50Mi
            requests:
              cpu: 10m
              memory: 50Mi
      containers:
        - name: socketcluster
          image: 'socketcluster/socketcluster:v14.3.0'
          ports:
            - containerPort: 8000
          env:
            - name: SCC_STATE_SERVER_HOST
              value: my-project-scc-state
            - name: SCC_INSTANCE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: SOCKETCLUSTER_WORKER_CONTROLLER
              value: /usr/src/app/worker.js
            - name: SOCKETCLUSTER_MASTER_CONTROLLER
              value: /usr/src/app/server.js
            # ... other envs
          resources:
            limits:
              cpu: 100m
              memory: 360Mi
            requests:
              cpu: 100m
              memory: 360Mi
          livenessProbe:
            httpGet:
              path: /health-check
              port: 8000
            initialDelaySeconds: 300
            timeoutSeconds: 5
          volumeMounts:
            - mountPath: /usr/src/app
              name: src-volume
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - my-project-scc
              topologyKey: kubernetes.io/hostname
      volumes:
        - name: src-volume
          emptyDir: {}

The container is only started when the init container has finished. I was using that until recently, having both as normal containers can cause some problems, and having to set the wait timeout to bigger values each time newer dependencies are added.

Recently I've ditched this deployment in favor of building my own socketcluster image with the correct dependencies already installed, since copying node_modules from the image to the volume was taking too long (almost 20 mins). But it's here as a suggestion.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing sample/dockerwait.js and the Kubernetes deployment example in the issue. Determine where the current deployment uses a separate source container and wait timeout, then verify that the source files are copied by an initContainer before the SocketCluster container starts.】【。

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, javascript, kubernetes
Domain
devops, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.