Running mongodb stateful set on Kubernetes with istio

10/29/2018

I am trying to setup mongodb on kubernetes with istio. My statefulset is as follows:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: treeservice
  namespace: staging
spec:
  serviceName: tree-service-service
  replicas: 1
  selector:
    matchLabels:
      app: treeservice
  template:
    metadata:
      labels:
        app: treeservice
    spec:
      containers:
      - name: mongodb-cache
        image: mongo:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 30010
        volumeMounts:
        - name: mongodb-cache-data
          mountPath: /data/db
        resources:
          requests:
            memory: "4Gi" # 4 GB
            cpu: "1000m"  # 1 CPUs
          limits:
            memory: "4Gi" # 4 GB
            cpu: "1000" #  1 CPUs    
        readinessProbe: 
          exec:
            command:
            - mongo
            - --eval "db.stats()" --port 30010
          initialDelaySeconds: 60 #wait this period after staring fist time
          periodSeconds: 30    # polling interval every 5 minutes
          timeoutSeconds: 60 
        livenessProbe: 
          exec:
            command:
            - mongo
            - --eval "db.stats()" --port 30010
          initialDelaySeconds: 60 #wait this period after staring fist time
          periodSeconds: 30    # polling interval every 5 minutes
          timeoutSeconds: 60   
        command: ["/bin/bash"]
        args: ["-c","mongod --port 30010 --replSet test"] #bind to localhost
  volumeClaimTemplates:
  - metadata:
      name: mongodb-cache-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: fast
      resources:
        requests:
          storage: 300Gi

however, the pod is not created and I see the following error:

kubectl describe statefulset treeservice -n staging

Warning  FailedCreate  1m (x159 over 1h)  statefulset-controller  create Pod treeservice-0 in StatefulSet treeservice failed error: Pod "treeservice-0" is invalid: spec.containers[1].env[7].name: Invalid value: "ISTIO_META_statefulset.kubernetes.io/pod-name": a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name',  or 'MY_ENV.NAME',  or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')      

I assum treeservice is a valid pod name. Am I missing something?

-- kosta
google-kubernetes-engine
kubernetes
kubernetes-statefulset

1 Answer

10/29/2018

I guess it's due to this issue https://github.com/istio/istio/issues/9571 which is still open

I made it work temporarily using the following:

annotations:
        sidecar.istio.io/inject: "false"
-- kosta
Source: StackOverflow