我有6个HTTP微服务。 目前他们运行在疯狂的bash /自定义部署工具设置(dokku,mup)。
我dockerized他们,并转移到AWS上的kubernetes(安装与kop)。 最后一块是转换我的nginxconfiguration。
我想要
我做了1. SSL终止将服务types设置为LoadBalancer并使用AWS特定的注释 。 这创build了AWS负载平衡器,但是对于其他需求来说 ,这似乎是一个死胡同 。
我看着Ingress,但是没有看到如何在AWS上完成。 这个Ingress控制器能在AWS上工作吗?
每个吊舱都需要一个nginx控制器吗? 这看起来很有趣,但我不确定它是多么新近/相关。
我不确定开始的方向。什么工作?
麦克风
你应该可以使用nginx入口控制器来完成这个任务。
自述文件向您介绍如何设置它,并且有很多例子 。
您需要完成这项工作的基本部分是:
最终的结果是,您将拥有与您的nginx入口控制器服务相对应的单个ELB,而后者则负责根据指定的入口规则路由到您的各个服务。
可能有更好的方法来做到这一点。 我写了这个答案,因为我问了这个问题。 这是最好的,我可以拿出像素大象的文档 链接 上面 。
缺省的http-backend对调试非常有用。 +1
入口
(减少占位符,因为没有“`)
apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: kubernetes.io/ingress.class: "nginx" name: all-ingress spec: tls: - hosts: - admin-stage.example.io secretName: tls-secret rules: - host: admin-stage.example.io http: paths: - backend: serviceName: admin servicePort: http-port path: / --- apiVersion: v1 data: enable-sticky-sessions: "true" proxy-read-timeout: "7200" proxy-send-imeout: "7200" kind: ConfigMap metadata: name: nginx-load-balancer-conf
应用服务和部署
(减少占位符,因为没有“`)
apiVersion: v1 kind: Service metadata: name: admin spec: ports: - name: http-port port: 80 protocol: TCP targetPort: http-port selector: app: admin sessionAffinity: ClientIP type: ClusterIP --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: admin spec: replicas: 1 template: metadata: labels: app: admin name: admin spec: containers: - image: example/admin:latest name: admin ports: - containerPort: 80 name: http-port resources: requests: cpu: 500m memory: 1000Mi volumeMounts: - mountPath: /etc/env-volume name: config readOnly: true imagePullSecrets: - name: cloud.docker.com-pull volumes: - name: config secret: defaultMode: 420 items: - key: admin.sh mode: 256 path: env.sh - key: settings.json mode: 256 path: settings.json secretName: env-secret
Ingress Nginx Docker Image
-v
以下 (减少占位符,因为没有“`)
apiVersion: v1 kind: Service metadata: name: nginx-ingress-service spec: ports: - name: http-port port: 80 protocol: TCP targetPort: http-port - name: https-port port: 443 protocol: TCP targetPort: https-port selector: app: nginx-ingress-service sessionAffinity: None type: LoadBalancer --- apiVersion: v1 kind: ReplicationController metadata: name: nginx-ingress-controller labels: k8s-app: nginx-ingress-lb spec: replicas: 1 selector: k8s-app: nginx-ingress-lb template: metadata: labels: k8s-app: nginx-ingress-lb name: nginx-ingress-lb spec: terminationGracePeriodSeconds: 60 containers: - image: gcr.io/google_containers/nginx-ingress-controller:0.8.3 name: nginx-ingress-lb imagePullPolicy: Always readinessProbe: httpGet: path: /healthz port: 10254 scheme: HTTP livenessProbe: httpGet: path: /healthz port: 10254 scheme: HTTP initialDelaySeconds: 10 timeoutSeconds: 1 # use downward API env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace ports: - name: http-port containerPort: 80 hostPort: 80 - name: https-port containerPort: 443 hostPort: 443 # we expose 18080 to access nginx stats in url /nginx-status # this is optional - containerPort: 18080 hostPort: 18080 args: - /nginx-ingress-controller - --default-backend-service=$(POD_NAMESPACE)/default-http-backend - --default-ssl-certificate=default/tls-secret - --nginx-configmap=$(POD_NAMESPACE)/nginx-load-balancer-conf - --v=2
默认后端(这是从.yaml文件复制/粘贴)
apiVersion: v1 kind: Service metadata: name: default-http-backend labels: k8s-app: default-http-backend spec: ports: - port: 80 targetPort: 8080 protocol: TCP name: http selector: k8s-app: default-http-backend --- apiVersion: v1 kind: ReplicationController metadata: name: default-http-backend spec: replicas: 1 selector: k8s-app: default-http-backend template: metadata: labels: k8s-app: default-http-backend spec: terminationGracePeriodSeconds: 60 containers: - name: default-http-backend # Any image is permissable as long as: # 1. It serves a 404 page at / # 2. It serves 200 on a /healthz endpoint image: gcr.io/google_containers/defaultbackend:1.0 livenessProbe: httpGet: path: /healthz port: 8080 scheme: HTTP initialDelaySeconds: 30 timeoutSeconds: 5 ports: - containerPort: 8080 resources: limits: cpu: 10m memory: 20Mi requests: cpu: 10m memory: 20Mi
这个配置使用三个秘密: