Kubernetes集群中使用ingress发布服务(2)

# cat nginx-ingress-controller.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-lb
  labels:
    name: nginx-ingress-lb
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: nginx-ingress-lb
      annotations:
        prometheus.io/port: '10254'
        prometheus.io/scrape: 'true'
    spec:
      terminationGracePeriodSeconds: 60
      hostNetwork: true
      containers:
      - image: docker.io/cdchen/nginx-ingress-controller:0.9.0-beta.12
        name: nginx-ingress-lb
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        ports:
        - containerPort: 80
          hostPort: 80
        - containerPort: 443
          hostPort: 443
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: KUBERNETES_MASTER
            value: :8080
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
        - --apiserver-host=http://192.168.115.5:8080

3、Dashboard 和 nginx的ingress yaml文件

# cat k8s-dashboard.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: k8s-dashboard-ingress
  namespace: default
spec:
  rules:
  - host: k8s.webui
    http:
      paths:
      - path: /
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 80# cat k8s-nginx-test.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: k8s-nginx-test
  namespace: default
spec:
  rules:
  - host: test.fjhb.cn
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx-test
          servicePort: 80

4、通过上述yaml文件创建对应的pod、rc及ingress

# kubectl get rc
# kubectl get pod
# cd ingress/
# kubectl create -f .

kubernetes集群中使用ingress发布服务

# kubectl get pod
# kubectl get ingress
# kubectl get rc

kubernetes集群中使用ingress发布服务


5、访问测试

kubernetes集群中使用ingress发布服务


kubernetes集群中使用ingress发布服务


kubernetes集群中使用ingress发布服务


kubernetes集群中使用ingress发布服务


也可以通过查看nginx-ingress-lb pod的日志来验证。

kubernetes集群中使用ingress发布服务

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/cbee1e7d2fcf8852da19b171e0e3bd94.html