快速部署和测试ingress-nginx:1.9.6

点击查看代码
下载deploy文件
https://github.com/kubernetes/ingress-nginx/blob/controller-v1.9.6/deploy/static/provider/cloud/deploy.yaml
修改deploy文件:
有如下几处可按需修改:

DaemonSet:修改 Deployment 为 DaemonSet,移除 strategy 字段;
hostNetwork:使用宿主机的网络;
nodeSelector:添加标签选择器(可选);
将名为 ingress-nginx-controller 的 Service 类型改为 ClusterIP(要删除 externalTrafficPolicy 字段);



点击查看代码
apiVersion: apps/v1
kind: DaemonSet  # 这里把 Deployment 改成 DaemonSet
metadata:
  labels:
    ...
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  minReadySeconds: 0
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/component: controller
        app.kubernetes.io/instance: ingress-nginx
        app.kubernetes.io/name: ingress-nginx
    spec:
      hostNetwork: true  #这里加一句
      # 移除 strategy
      nodeSelector: # 可选
        kubernetes.io/os: linux
        hasIngress: "true"  # 在存在这个标签的 node 上部署
      containers:
      - args:
        ...
部署一个最常用的http服务nginx,使用ingress-nginx暴露http服务 1、编写demo.yml
点击查看代码
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  serviceName: nginx
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: Always
        ports:
        - containerPort: 80
          name: port
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: nginx

点击查看代码
编写ingress-demo.yml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: nginx.text.cn
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: nginx
            port:
              number: 80

kubectl apply -f .

测试
image

忘记放固定端口的文件了:
service-nodeport.yaml

点击查看代码
apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: 80
      nodePort: 31188
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      nodePort: 30443
      protocol: TCP
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
镜像无法拉取的解决方式: https://www.cnblogs.com/zwnfdswww/p/18109879
posted @ 2024-04-20 20:47  惊世智慧  阅读(81)  评论(0编辑  收藏  举报