Kubernetes: ConfigMap ne fonctionnera pas autant qu'ENV

Créé le 7 févr. 2017  ·  2Commentaires  ·  Source: kubernetes/kubernetes

Environnement :

Cluster de conteneurs GCP

Version Kube :

kubectl version
Client Version: version.Info{Major:"1", Minor:"3", GitVersion:"v1.3.7", GitCommit:"a2cba278cba1f6881bb0a7704d9cac6fca6ed435", GitTreeState:"clean", BuildDate:"2016-09-12T23:15:30Z", GoVersion:"go1.6.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.8", GitCommit:"c5fcb1951afb8150e4574bc234aed957cb586eb0", GitTreeState:"clean", BuildDate:"2017-01-12T02:14:29Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}

Dans notre projet, nous essayions d'utiliser massivement les Configmaps/secrets.

Cela fonctionne lorsque nous consommons les configmaps en tant que "plugin Voulme". Mais cela ne fonctionnera pas s'il consomme en tant qu'ENV.

root<strong i="14">@localhost</strong> env-dir]# cat bcsp-env
discovery_app=discovery
discovery_port=8761

kubectl get configmaps bcsp-var -o yaml
apiVersion: v1
data:
  bcsp-env: |
    discovery_app=discovery
    discovery_port=8761
kind: ConfigMap
metadata:
  creationTimestamp: 2017-02-07T14:33:50Z
  name: bcsp-var
  namespace: default
  resourceVersion: "1689350"
  selfLink: /api/v1/namespaces/default/configmaps/bcsp-var
  uid: 7153f6a7-ed42-11e6-b230-42010af00056

Je l'ai essayé dans notre application dans le modèle de déploiement, cela ne fonctionnera pas. Je prends donc un exemple sur le site kubernetes et teste via busybox.

cat test.yml
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: test-container
      image: gcr.io/google_containers/busybox
      command: [ "/bin/sh", "-c", "echo $(DISCOVERY_APP) $(DISCOVERY_PORT)" ]
      env:
        - name: DISCOVERY_APP
          valueFrom:
            configMapKeyRef:
              name: bcsp-var
              key: discovery_app
        - name: DISCOVERY_PORT
          valueFrom:
            configMapKeyRef:
              name: bcsp-var
              key: discovery_port
  restartPolicy: Never

Le pod a échoué avec les messages ci-dessous

kubectl describe pod test-pod
Name:           test-pod
Namespace:      default
Node:           gke-container-cluster-it-default-pool-e1732b12-jn5c/10.242.153.2
Start Time:     Tue, 07 Feb 2017 06:34:51 -0800
Labels:         <none>
Status:         Pending
IP:             10.8.1.21
Controllers:    <none>
Containers:
  test-container:
    Container ID:
    Image:              gcr.io/google_containers/busybox
    Image ID:
    Port:
    Command:
      /bin/sh
      -c
      echo $(DISCOVERY_APP) $(DISCOVERY_PORT)
    Requests:
      cpu:              100m
    State:              Waiting
      Reason:           RunContainerError
    Ready:              False
    Restart Count:      0
    Environment Variables:
      DISCOVERY_APP:    <set to the key 'discovery_app' of config map 'bcsp-var'>
      DISCOVERY_PORT:   <set to the key 'discovery_port' of config map 'bcsp-var'>
Conditions:
  Type          Status
  Initialized   True
  Ready         False
  PodScheduled  True
Volumes:
  default-token-1u3vc:
    Type:       Secret (a volume populated by a Secret)
    SecretName: default-token-1u3vc
QoS Tier:       Burstable
Events:
  FirstSeen     LastSeen        Count   From                                                            SubobjectPath                   Type            Reason          Message
  ---------     --------        -----   ----                                                            -------------                   --------        ------          -------
  26s           26s             1       {default-scheduler }                                                                            Normal          Scheduled       Successfully assigned test-pod to gke-container-cluster-it-default-pool-e1732b12-jn5c
  26s           9s              3       {kubelet gke-container-cluster-it-default-pool-e1732b12-jn5c}   spec.containers{test-container} Normal          Pulling         pulling image "gcr.io/google_containers/busybox"
  25s           8s              3       {kubelet gke-container-cluster-it-default-pool-e1732b12-jn5c}   spec.containers{test-container} Normal          Pulled          Successfully pulled image "gcr.io/google_containers/busybox"
  25s           8s              3       {kubelet gke-container-cluster-it-default-pool-e1732b12-jn5c}                                   Warning         FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "test-container" with RunContainerError: "GenerateRunContainerOptions: Couldn't find key discovery_app in ConfigMap default/bcsp-var"

areconfigmap-api

Commentaire le plus utile

Le nom du fichier est pris comme clé pour configmap. J'ai fait la mauvaise implémentation.

Tous les 2 commentaires

Le nom du fichier est pris comme clé pour configmap. J'ai fait la mauvaise implémentation.

@talk2vino Alors, quelle est la syntaxe à utiliser dans les pods. Moi aussi j'ai ce problème !

Cette page vous a été utile?
0 / 5 - 0 notes

Questions connexes

rhohubbuild picture rhohubbuild  ·  3Commentaires

arun-gupta picture arun-gupta  ·  3Commentaires

theothermike picture theothermike  ·  3Commentaires

tbchj picture tbchj  ·  3Commentaires

ddysher picture ddysher  ·  3Commentaires