2017-02-15 2 views
0

ich mit Kubernetes bin herumgespielt und ich habe meine Umgebung mit 4-Installationen einzurichten:Loadbalancer-Dienst nicht auf dem gewünschten pod umleiten

  • hello: basic "Hallo Welt" Service
  • auth: ermöglicht die Authentifizierung und Verschlüsselung
  • Frontend: ein nginx Reverse-Proxy, der eine Single-Point-of-Entry von außen und Strecken, um die genauen Schoten stellt intern
  • nodehello: basic "hallo, Welt" Service, in dem Knoten geschrieben js (das ist, was ich trug)

Für die hello, auth und nodehello Implementierungen Ich habe jeden internen Dienst einrichten.

Für die frontend Bereitstellung habe ich einen Load-Balancer-Dienst eingerichtet, der der Außenwelt ausgesetzt wäre. Es verwendet eine Konfigurationskarte nginx-frontend-conf an den entsprechenden Hülsen zu umleiten und hat folgenden Inhalt:

upstream hello { 
    server hello.default.svc.cluster.local; 
} 
upstream auth { 
    server auth.default.svc.cluster.local; 
} 
upstream nodehello { 
    server nodehello.default.svc.cluster.local; 
}   
server { 
    listen 443; 
    ssl on; 
    ssl_certificate  /etc/tls/cert.pem; 
    ssl_certificate_key /etc/tls/key.pem; 
    location/{ 
     proxy_pass http://hello; 
    } 
    location /login { 
     proxy_pass http://auth; 
    } 
    location /nodehello { 
     proxy_pass http://nodehello; 
    } 
} 

Wenn der Frontend Endpunkt Aufruf curl -k https://<frontend-external-ip> mit I an einen verfügbaren hello pod geroutet, die das erwartete Verhalten ist. Beim Aufruf https://<frontend-external-ip>/nodehello jedoch werde ich nicht zu einem nodehello Pod weitergeleitet, sondern stattdessen zu einem hellopod wieder.

Ich vermute, dass die upstream nodehello Konfiguration der fehlgeschlagene Teil ist. Ich bin mir nicht sicher, wie Service Discovery hier funktioniert, d. H. Wie der DNS-Name nodehello.default.svc.cluster.local ausgesetzt würde. Ich würde mich über eine Erklärung freuen, wie es funktioniert und was ich falsch gemacht habe.

yaml Dateien verwendet

Einsätze/hello.yaml

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: hello 
spec: 
    replicas: 3 
    template: 
    metadata: 
     labels: 
     app: hello 
     track: stable 
    spec: 
     containers: 
     - name: hello 
      image: "udacity/example-hello:1.0.0" 
      ports: 
      - name: http 
       containerPort: 80 
      - name: health 
       containerPort: 81 
      resources: 
      limits: 
       cpu: 0.2 
       memory: "10Mi" 
      livenessProbe: 
      httpGet: 
       path: /healthz 
       port: 81 
       scheme: HTTP 
      initialDelaySeconds: 5 
      periodSeconds: 15 
      timeoutSeconds: 5 
      readinessProbe: 
      httpGet: 
       path: /readiness 
       port: 81 
       scheme: HTTP 
      initialDelaySeconds: 5 
      timeoutSeconds: 1 

Einsätze/auth.yaml

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: auth 
spec: 
    replicas: 1 
    template: 
    metadata: 
     labels: 
     app: auth 
     track: stable 
    spec: 
     containers: 
     - name: auth 
      image: "udacity/example-auth:1.0.0" 
      ports: 
      - name: http 
       containerPort: 80 
      - name: health 
       containerPort: 81 
      resources: 
      limits: 
       cpu: 0.2 
       memory: "10Mi" 
      livenessProbe: 
      httpGet: 
       path: /healthz 
       port: 81 
       scheme: HTTP 
      initialDelaySeconds: 5 
      periodSeconds: 15 
      timeoutSeconds: 5 
      readinessProbe: 
      httpGet: 
       path: /readiness 
       port: 81 
       scheme: HTTP 
      initialDelaySeconds: 5 
      timeoutSeconds: 1 

Einsätze/frontend.yaml

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: frontend 
spec: 
    replicas: 1 
    template: 
    metadata: 
     labels: 
     app: frontend 
     track: stable 
    spec: 
     containers: 
     - name: nginx 
      image: "nginx:1.9.14" 
      lifecycle: 
      preStop: 
       exec: 
       command: ["/usr/sbin/nginx","-s","quit"] 
      volumeMounts: 
      - name: "nginx-frontend-conf" 
       mountPath: "/etc/nginx/conf.d" 
      - name: "tls-certs" 
       mountPath: "/etc/tls" 
     volumes: 
     - name: "tls-certs" 
      secret: 
      secretName: "tls-certs" 
     - name: "nginx-frontend-conf" 
      configMap: 
      name: "nginx-frontend-conf" 
      items: 
       - key: "frontend.conf" 
       path: "frontend.conf" 

Einsätze/nodehello.yaml

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: nodehello 
spec: 
    replicas: 1 
    template: 
    metadata: 
     labels: 
     app: nodehello 
     track: stable 
    spec: 
     containers: 
     - name: nodehello 
      image: "thezebra/nodehello:0.0.2" 
      ports: 
      - name: http 
       containerPort: 80 
      resources: 
      limits: 
       cpu: 0.2 
       memory: "10Mi" 

services/hello.yaml

kind: Service 
apiVersion: v1 
metadata: 
    name: "hello" 
spec: 
    selector: 
    app: "hello" 
    ports: 
    - protocol: "TCP" 
     port: 80 
     targetPort: 80 

services/auth.yaml

kind: Service 
apiVersion: v1 
metadata: 
    name: "auth" 
spec: 
    selector: 
    app: "auth" 
    ports: 
    - protocol: "TCP" 
     port: 80 
     targetPort: 80 

Dienste/Frontend.yaml

kind: Service 
apiVersion: v1 
metadata: 
    name: "frontend" 
spec: 
    selector: 
    app: "frontend" 
    ports: 
    - protocol: "TCP" 
     port: 443 
     targetPort: 443 
    type: LoadBalancer 

services/nodehello.yaml

kind: Service 
apiVersion: v1 
metadata: 
    name: "nodehello" 
spec: 
    selector: 
    app: "nodehello" 
    ports: 
    - protocol: "TCP" 
     port: 80 
     targetPort: 80 
+1

Bitte geben Sie die verwendeten yaml-Dateien an. –

+0

@FarhadFarahi yaml Dateien hinzugefügt – Ronin

Antwort

0

Das funktioniert perfekt :-)

$ curl -s http://frontend/ 
{"message":"Hello"} 
$ curl -s http://frontend/login 
authorization failed 
$ curl -s http://frontend/nodehello 
Hello World! 

Ich vermute, Sie könnten die nginx-Frontend-conf aktualisiert wenn Sie/nodehello hinzugefügt haben, aber nginx nicht neu gestartet haben. Pods übernehmen geänderte ConfigMaps nicht automatisch. Versuchen Sie:

Bis versioned ConfigMaps passieren, gibt es keine bessere Lösung.

Verwandte Themen