Created
September 6, 2018 12:04
-
-
Save foxutech/a5605314ba24add1fed2ca91eef72cb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # kubectl create -f https://raw.githubusercontent.com/kubernetes/contrib/master/ingress/controllers/nginx/examples/default-backend.yaml | |
| # kubectl expose rc default-http-backend --port=80 --target-port=8080 --name=default-http-backend | |
| Create a file nginx-ingress-controller.yml with following content | |
| =======File Start================ | |
| apiVersion: v1 | |
| kind: Service | |
| metadata: | |
| name: nginx-ingress | |
| spec: | |
| type: nodePort | |
| ports: | |
| - port: 80 | |
| name: http | |
| - port: 443 | |
| name: https | |
| selector: | |
| k8s-app: nginx-ingress-lb | |
| --- | |
| apiVersion: extensions/v1beta1 | |
| kind: Deployment | |
| metadata: | |
| name: nginx-ingress-controller | |
| spec: | |
| replicas: 2 | |
| revisionHistoryLimit: 3 | |
| template: | |
| metadata: | |
| labels: | |
| k8s-app: nginx-ingress-lb | |
| spec: | |
| terminationGracePeriodSeconds: 60 | |
| containers: | |
| - name: nginx-ingress-controller | |
| image: gcr.io/google_containers/nginx-ingress-controller:0.8.3 | |
| imagePullPolicy: Always | |
| readinessProbe: | |
| httpGet: | |
| path: /healthz | |
| port: 18080 | |
| scheme: HTTP | |
| livenessProbe: | |
| httpGet: | |
| path: /healthz | |
| port: 18080 | |
| scheme: HTTP | |
| initialDelaySeconds: 10 | |
| timeoutSeconds: 5 | |
| args: | |
| - /nginx-ingress-controller | |
| - --default-backend-service=$(POD_NAMESPACE)/default-http-backend | |
| - --default-ssl-certificate=$(POD_NAMESPACE)/tls-certificate | |
| # Use downward API | |
| env: | |
| - name: POD_NAME | |
| valueFrom: | |
| fieldRef: | |
| fieldPath: metadata.name | |
| - name: POD_NAMESPACE | |
| valueFrom: | |
| fieldRef: | |
| fieldPath: metadata.namespace | |
| ports: | |
| - containerPort: 80 | |
| - containerPort: 443 | |
| volumeMounts: | |
| - name: tls-dhparam-vol | |
| mountPath: /etc/nginx-ssl/dhparam | |
| - name: nginx-template-volume | |
| mountPath: /etc/nginx/template | |
| readOnly: true | |
| volumes: | |
| - name: tls-dhparam-vol | |
| secret: | |
| secretName: tls-dhparam | |
| - name: nginx-template-volume | |
| configMap: | |
| name: nginx-template | |
| items: | |
| - key: nginx.tmpl | |
| path: nginx.tmpl | |
| =======File End================== | |
| # kubectl create -f ./nginx-ingress-controller.yml | |
| # kubectl get services -o wide | grep nginx | |
| Create a ingress file (# ingress.yaml) | |
| =============file start================== | |
| apiVersion: extensions/v1beta1 | |
| kind: Ingress | |
| metadata: | |
| name: ingress-nginx | |
| namespace: default | |
| annotations: | |
| kubernetes.io/ingress.class: "nginx" | |
| spec: | |
| rules: | |
| - host: "webserver.localhost" | |
| http: | |
| paths: | |
| - path: /sample | |
| backend: | |
| serviceName: tomcat service name | |
| servicePort: 8080 | |
| - host: "webhook.localhost" | |
| http: | |
| paths: | |
| - path: / | |
| backend: | |
| serviceName: nginx service name | |
| servicePort: 80 | |
| =============file end==================== | |
| Also add the domain entry to # /etc/hosts file. | |
| ex: | |
| IP Domain name | |
| x.x.x.x webhook.localhost | |
| x.x.x.x webserver.localhost | |
| then run the ingress.yaml file. | |
| and check the output in # kubectl get ing -n namespace | |
| now you should curl the domains. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment