Kubernetes的Ingress Controller

前言

Kubernetes暴露服务的方式有一下几种:LoadBlancer Service、ExternalName、NodePort Service、Ingress,使用四层负载均衡调度器Service时,当客户端访问kubernetes集群内部的应用时,数据包的走向如下面流程所示:Client——>NodeIp:Port——>ServiceIp:Port——>PodIp:Port。四层代理的时候我们需要在服务暴露端口,过多的业务暴露过多的端口对服务器来说是一种安全风险。

Ingress是Kubernetes中的一个AP对象,属于七层代理用于管理HTTP和HTTPS流量的路由规则。它充当了集群内部服务与外部流量之间的网关,允许将外部请求路由到集群内部的不同服务上。他有多种控制器如:NGINX Ingress Controller、Traefik Ingress Controller、HAProxy Ingress Controller、Contour Ingress Controller等。

NGINX Ingress Controller

Ingress-nginx是将Nginx的配置抽象成一个Ingress对象,每添加一个新的服务只需写一个新的Ingress的yaml文件。它的工作原理是:

  1. ingress controller通过和kubernetes api交互,动态的去感知集群中Ingress规则变化。
  2. 然后读取它,按照自定义的规则,规则就是写明了哪个域名对应哪个service,生成一段nginx配置.
  3. 再写到nginx-ingress-control的pod里,这个Ingress controller的pod里运行着一个Nginx服务,控制器会把生成的nginx配置写入nginx的配置文件中。
  4. 然后reload一下使配置生效。以此达到域名分配置和动态更新的问题。
    在这里插入图片描述

部署Ingress Controller

官方地址:https://github.com/kubernetes/ingress-nginx
镜像下载代理地址:https://dockerproxy.com/

部署文件路径:ingress-nginx-release-1.10\deploy\static\provider\baremetal\delop.yaml(我是从Github把包下载下来了)

官方Kubernetes和Ingress的版本对应:
在这里插入图片描述

我的Kubernetes是1.28.7所以选择了ingress-nginx-release-1.10。

修改YAML文件Service部分,它有两个Service修改类型为type:NodePort部分的Service如下

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
    nodePort: 30080
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
    nodePort: 30443
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: NodePort

修改镜像image,文件中有三个image位置共两个镜像

#image: registry.k8s.io/ingress-nginx/controller:v1.10.0@sha256:42b3f0e5d0846876b1791cd3afeb5f1cbbe4259d6f35651dcc1b5c980925379c
image: k8s.dockerproxy.com/ingress-nginx/controller:v1.10.0

#image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.0@sha256:44d1d0e9f19c63f58b380c5fddaca7cf22c7cee564adeff365225a5df5ef3334
image: k8s.dockerproxy.com/ingress-nginx/kube-webhook-certgen:v1.4.0

修改完成的YAML:

apiVersion: v1
kind: Namespace
metadata:
  labels:
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  name: ingress-nginx
---
apiVersion: v1
automountServiceAccountToken: true
kind: ServiceAccount
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx
  namespace: ingress-nginx
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission
  namespace: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx
  namespace: ingress-nginx
rules:
- apiGroups:
  - ""
  resources:
  - namespaces
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - configmaps
  - pods
  - secrets
  - endpoints
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - services
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - networking.k8s.io
  resources:
  - ingresses
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - networking.k8s.io
  resources:
  - ingresses/status
  verbs:
  - update
- apiGroups:
  - networking.k8s.io
  resources:
  - ingressclasses
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - coordination.k8s.io
  resourceNames:
  - ingress-nginx-leader
  resources:
  - leases
  verbs:
  - get
  - update
- apiGroups:
  - coordination.k8s.io
  resources:
  - leases
  verbs:
  - create
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - patch
- apiGroups:
  - discovery.k8s.io
  resources:
  - endpointslices
  verbs:
  - list
  - watch
  - get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission
  namespace: ingress-nginx
rules:
- apiGroups:
  - ""
  resources:
  - secrets
  verbs:
  - get
  - create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx
rules:
- apiGroups:
  - ""
  resources:
  - configmaps
  - endpoints
  - nodes
  - pods
  - secrets
  - namespaces
  verbs:
  - list
  - watch
- apiGroups:
  - coordination.k8s.io
  resources:
  - leases
  verbs:
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - services
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - networking.k8s.io
  resources:
  - ingresses
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - patch
- apiGroups:
  - networking.k8s.io
  resources:
  - ingresses/status
  verbs:
  - update
- apiGroups:
  - networking.k8s.io
  resources:
  - ingressclasses
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - discovery.k8s.io
  resources:
  - endpointslices
  verbs:
  - list
  - watch
  - get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission
rules:
- apiGroups:
  - admissionregistration.k8s.io
  resources:
  - validatingwebhookconfigurations
  verbs:
  - get
  - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx
  namespace: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: ingress-nginx
subjects:
- kind: ServiceAccount
  name: ingress-nginx
  namespace: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission
  namespace: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: ingress-nginx-admission
subjects:
- kind: ServiceAccount
  name: ingress-nginx-admission
  namespace: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: ingress-nginx
subjects:
- kind: ServiceAccount
  name: ingress-nginx
  namespace: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: ingress-nginx-admission
subjects:
- kind: ServiceAccount
  name: ingress-nginx-admission
  namespace: ingress-nginx
---
apiVersion: v1
data:
  allow-snippet-annotations: "false"
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
    nodePort: 30080
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
    nodePort: 30443
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-controller-admission
  namespace: ingress-nginx
spec:
  ports:
  - appProtocol: https
    name: https-webhook
    port: 443
    targetPort: webhook
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  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
  strategy:
    rollingUpdate:
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/component: controller
        app.kubernetes.io/instance: ingress-nginx
        app.kubernetes.io/name: ingress-nginx
        app.kubernetes.io/part-of: ingress-nginx
        app.kubernetes.io/version: 1.10.0
    spec:
      containers:
      - args:
        - /nginx-ingress-controller
        - --election-id=ingress-nginx-leader
        - --controller-class=k8s.io/ingress-nginx
        - --ingress-class=nginx
        - --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
        - --validating-webhook=:8443
        - --validating-webhook-certificate=/usr/local/certificates/cert
        - --validating-webhook-key=/usr/local/certificates/key
        - --enable-metrics=false
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: LD_PRELOAD
          value: /usr/local/lib/libmimalloc.so
        #image: registry.k8s.io/ingress-nginx/controller:v1.10.0@sha256:42b3f0e5d0846876b1791cd3afeb5f1cbbe4259d6f35651dcc1b5c980925379c
        image: k8s.dockerproxy.com/ingress-nginx/controller:v1.10.0
        imagePullPolicy: IfNotPresent
        lifecycle:
          preStop:
            exec:
              command:
              - /wait-shutdown
        livenessProbe:
          failureThreshold: 5
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: controller
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        - containerPort: 443
          name: https
          protocol: TCP
        - containerPort: 8443
          name: webhook
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 100m
            memory: 90Mi
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            add:
            - NET_BIND_SERVICE
            drop:
            - ALL
          readOnlyRootFilesystem: false
          runAsNonRoot: true
          runAsUser: 101
          seccompProfile:
            type: RuntimeDefault
        volumeMounts:
        - mountPath: /usr/local/certificates/
          name: webhook-cert
          readOnly: true
        - mountPath: /etc/localtime
          name: time
          readOnly: true
      dnsPolicy: ClusterFirst
      nodeSelector:
        kubernetes.io/os: linux
      serviceAccountName: ingress-nginx
      terminationGracePeriodSeconds: 300
      volumes:
      - name: webhook-cert
        secret:
          secretName: ingress-nginx-admission
      - name: time 
        hostPath: 
          path: /etc/localtime
          type: File
---
apiVersion: batch/v1
kind: Job
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission-create
  namespace: ingress-nginx
spec:
  template:
    metadata:
      labels:
        app.kubernetes.io/component: admission-webhook
        app.kubernetes.io/instance: ingress-nginx
        app.kubernetes.io/name: ingress-nginx
        app.kubernetes.io/part-of: ingress-nginx
        app.kubernetes.io/version: 1.10.0
      name: ingress-nginx-admission-create
    spec:
      containers:
      - args:
        - create
        - --host=ingress-nginx-controller-admission,ingress-nginx-controller-admission.$(POD_NAMESPACE).svc
        - --namespace=$(POD_NAMESPACE)
        - --secret-name=ingress-nginx-admission
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        #image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.0@sha256:44d1d0e9f19c63f58b380c5fddaca7cf22c7cee564adeff365225a5df5ef3334
        image: k8s.dockerproxy.com/ingress-nginx/kube-webhook-certgen:v1.4.0
        imagePullPolicy: IfNotPresent
        name: create
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 65532
          seccompProfile:
            type: RuntimeDefault
        volumeMounts:      
        - mountPath: /etc/localtime
          name: time
          readOnly: true
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: OnFailure
      serviceAccountName: ingress-nginx-admission
      volumes:
      - name: time 
        hostPath: 
          path: /etc/localtime
          type: File
---
apiVersion: batch/v1
kind: Job
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission-patch
  namespace: ingress-nginx
spec:
  template:
    metadata:
      labels:
        app.kubernetes.io/component: admission-webhook
        app.kubernetes.io/instance: ingress-nginx
        app.kubernetes.io/name: ingress-nginx
        app.kubernetes.io/part-of: ingress-nginx
        app.kubernetes.io/version: 1.10.0
      name: ingress-nginx-admission-patch
    spec:
      containers:
      - args:
        - patch
        - --webhook-name=ingress-nginx-admission
        - --namespace=$(POD_NAMESPACE)
        - --patch-mutating=false
        - --secret-name=ingress-nginx-admission
        - --patch-failure-policy=Fail
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        #image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.0@sha256:44d1d0e9f19c63f58b380c5fddaca7cf22c7cee564adeff365225a5df5ef3334
        image: k8s.dockerproxy.com/ingress-nginx/kube-webhook-certgen:v1.4.0
        imagePullPolicy: IfNotPresent
        name: patch
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 65532
          seccompProfile:
            type: RuntimeDefault
        volumeMounts:      
        - mountPath: /etc/localtime
          name: time
          readOnly: true
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: OnFailure
      serviceAccountName: ingress-nginx-admission
      volumes:
      - name: time 
        hostPath: 
          path: /etc/localtime
          type: File
---
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: nginx
spec:
  controller: k8s.io/ingress-nginx
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  labels:
    app.kubernetes.io/component: admission-webhook
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.10.0
  name: ingress-nginx-admission
webhooks:
- admissionReviewVersions:
  - v1
  clientConfig:
    service:
      name: ingress-nginx-controller-admission
      namespace: ingress-nginx
      path: /networking/v1/ingresses
  failurePolicy: Fail
  matchPolicy: Equivalent
  name: validate.nginx.ingress.kubernetes.io
  rules:
  - apiGroups:
    - networking.k8s.io
    apiVersions:
    - v1
    operations:
    - CREATE
    - UPDATE
    resources:
    - ingresses
  sideEffects: None

部署完成查看状态:

[root@master back]# kubectl get svc,pod -n ingress-nginx
NAME                                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             NodePort    10.100.169.162   <none>        80:30080/TCP,443:30443/TCP   5h41m
service/ingress-nginx-controller-admission   ClusterIP   10.100.239.92    <none>        443/TCP                      5h41m

NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-5rgbk        0/1     Completed   0          5h41m
pod/ingress-nginx-admission-patch-9glvg         0/1     Completed   0          5h41m
pod/ingress-nginx-controller-7b498f7d8c-7j2qd   1/1     Running     0          5h41m

创建Ingress资源

Ingress资源是基于HTTP虚拟主机或URL的转发规则,需要强调的是,这是一条转发规则。它在资源配置清单中的spec字段中嵌套了rules、backend和tls等字段进行定义。

  1. rules:用于定义当前Ingress资源的转发规则列表;由rules定义规则,或没有匹配到规则时,所有的流量会转发到由backend定义的默认后端。它是一个对象列表。
  2. backend:默认的后端用于服务那些没有匹配到任何规则的请求;定义Ingress资源时,必须要定义backend或rules两者之一,该字段用于让负载均衡器指定一个全局默认的后端。
  3. tls:TLS配置,目前仅支持通过默认端口443提供服务,如果要配置指定的列表成员指向不同的主机,则需要通过SNI TLS扩展机制来支持该功能。

部署一个Delopment的nginx服务

apiVersion: v1
kind: Service
metadata: 
  name: nginx-test
  namespace: default
spec:
  ports:
  - name: nginx 
    targetPort: 80
    port: 80
  selector:
    ser: nginx-test

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-dy
  labels:
    web: nginx
  namespace: default
  annotations:
    dac: " image version to v1.0"
spec:
  minReadySeconds: 10
  #新创建的Pod成为就绪状态之前,Deployment控制器等待的最短时间(秒数)。确保Pod中的业务程序能正常工作之前有做狗的时候完成初始化和准备工作。
  paused: false
  progressDeadlineSeconds: 60
  #该字段用于指定部署操作的进度检查的超时时间(以秒为单位)。这个字段的作用是为了确保部署操作能够在指定的时间内完成,并在超时后进行相应的处理。
  replicas: 4
  revisionHistoryLimit: 5
  #该用于指定要保留的 Deployment 版本历史记录的最大数量。Deployment 版本历史记录包含了过去创建的每个 Deployment 的详细信息,包括创建时间、更新时间、副本数量等。
  #如果设置为 0,则不会保留任何历史记录;如果设置为负值,则表示将保留所有历史记录。
  selector:
    matchLabels:
      ser: nginx-test
  strategy:
  #定义滚动更新策略
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      name: nginx
      #namespeace
      labels:
        ser: nginx-test
    spec:
      # nodeSelector:
      #   app: to
      hostname: nginx-dy
      containers:
      - image: docker.io/library/nginx:v1
        name: nginx-dy
        imagePullPolicy: IfNotPresent
        ports:
        - name: nginx-post
          containerPort: 80
        # volumeMounts:
        # - name: nginx-conf
        #   mountPath: /etc/nginx/conf.d
        #   readOnly: false
        #   #为true为只读方式挂载
      # volumes:
      # - name: nginx-conf
      #   emptyDir: {}
        
          

        

部署Igress

apiVersion: networking.k8s.io/v1        #api版本
kind: Ingress           #清单类型
metadata:                       #元数据
  name: ingress-my   #ingress的名称
  namespace: default     #所属名称空间
spec:      
  ingressClassName: nginx
  # tls:
  # - hosts: 
  #   - nginx.bwk.com
  #   secretName: nginx-ingress-secret
  rules:   #定义后端转发的规则
  - host: nginx.bwk.com    #通过域名进行转发
    http:
      paths:       
      - path: /   #配置访问路径(客户端的访问,请求的路径),如果通过url进行转发,需要修改;空默认为访问的路径为"/"
        pathType: Prefix  #   匹配的方式  
        backend:    #配置后端服务
          service:
            name: nginx-test
            port:
              number: 80    


  1. ingress.spec.rules.http.paths.path和ingress.spec.rules.http.paths.pathType两个字段定义的是客户端的访问请求的路径和路径的匹配方式。
  2. ingress.spec.rules.http.paths.pathType路径的匹配方式:
  • Prefix(前缀匹配): 当请求的路径以指定的路径前缀开头时,将匹配该路径规则。例如:/app、/app/subpath 等都将匹配/app的前缀路径规则。
  • Exact(完全匹配): 只有当请求的路径与指定的路径完全相同时,才会匹配该路径规则。例如:只有请求的路径是/app时才会匹配/app的完全路径规则。
  • ImplementationSpecific 时,Ingress控制器会根据其特定的实现逻辑来确定如何匹配请求的路径。这意味着路径的匹配方式可能因不同的Ingress控制器而异。
  • ingressClassName:Ingress控制器。此处用的是NGINX Ingress Controller。
  1. 配置一个虚拟域名nginx.bwk.com。

部署后访问测试:

[root@localhost k8s]# curl nginx.bwk.com:30080
v1

nginx页面进行了修改访问结果就是V1

部署TLS Igress

  • 创建Secret

    openssl genrsa -out tls.key 2048
    openssl req -new -x509 -key ./tls.key -out tls.crt -subj /C=CN/ST=Beijing/L=Beijing/O=DevOps/CN=nginx.bwk.com
    kubectl create secret tls nginx-ingress-secret --cert=./tls.crt --key=./tls.key

查看Secret

[root@master ~]# kubectl describe secret nginx-ingress-secret
Name:         nginx-ingress-secret
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  kubernetes.io/tls

Data
====
tls.crt:  1285 bytes
tls.key:  1679 bytes
[root@master ~]# 
  • 部署ingress
apiVersion: networking.k8s.io/v1        #api版本
kind: Ingress           #清单类型
metadata:                       #元数据
  name: ingress-my   #ingress的名称
  namespace: default     #所属名称空间
spec:      
  ingressClassName: nginx
  tls:
  - hosts: 
    - nginx.bwk.com
    secretName: nginx-ingress-secret
  rules:   #定义后端转发的规则
  - host: nginx.bwk.com    #通过域名进行转发
    http:
      paths:       
      - path: /   #配置访问路径(客户端的访问,请求的路径),如果通过url进行转发,需要修改;空默认为访问的路径为"/"
        pathType: Prefix  #   匹配的方式  
        backend:    #配置后端服务
          service:
            name: nginx-test
            port:
              number: 80    


去掉yaml文件的注释部署
部署测试拷贝证书到测试主机

[root@localhost home]# curl --cacert ./tls.crt  https://nginx.bwk.com:30443
v1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/544691.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

计算机三级数据库技术备考笔记(十四)

第十四章 数据仓库与数据挖掘 决策支持系统的发展 决策支持系统及其演化 操作型数据(Operalional Data)是指由企业的基本业务系统所产生的数据,操作型数据及相应数据处理所处的环境,即用于支持企业基本业务应用的环境,一般被称为联机事务处理(0nLine Transaction Processing,0…

COMSOL多孔介质流仿真

使用Comsol进行多孔介质流仿真_哔哩哔哩_bilibili 目录 多孔介质 饱和多孔介质中的流动 达西定律 Brinkman方程&#xff1a;用于过渡区 裂隙流 变饱和多孔介质流 理查兹方程 多孔介质多相流 多物理场耦合 多孔介质中的传热 多孔弹性接口 多孔介质稀物质传递 多孔介质…

c# 无处不在的二分搜索

我们知道二分查找算法。二分查找是最容易正确的算法。我提出了一些我在二分搜索中收集的有趣问题。有一些关于二分搜索的请求。我请求您遵守准则&#xff1a;“我真诚地尝试解决问题并确保不存在极端情况”。阅读完每个问题后&#xff0c;最小化浏览器并尝试解决它。 …

NSL-KDD数据集详细介绍及下载

链接&#xff1a;https://pan.baidu.com/s/1hX4xpVPo70vwLIo0gdsM8A?pwdq88b 提取码&#xff1a;q88b 一般认为数据质量决定了机器学习性能的上限,而机器学习模型和算法的优化最多 只能逼近这个上限。因此在数据采集阶段需要对采集任务进行规划。在数据采集之前, 主要是从数据…

第十二讲 查询计划 优化

到目前为止&#xff0c;我们一直在说&#xff0c;我们得到一个 SQL 查询&#xff0c;我们希望可以解析它&#xff0c;将其转化为某种逻辑计划&#xff0c;然后生成我们可以用于执行的物理计划。而这正是查询优化器【Optimizer】的功能&#xff0c;对于给定的 SQL &#xff0c;优…

.net框架和c#程序设计第三次测试

目录 一、测试要求 二、实现效果 三、实现代码 一、测试要求 二、实现效果 数据库中的内容&#xff1a; 使用数据库中的账号登录&#xff1a; 若不是数据库中的内容&#xff1a; 三、实现代码 login.aspx文件&#xff1a; <% Page Language"C#" AutoEventW…

DB schema表中使用全局变量及在DB组件中查询

DB schema表中使用全局变量及在DB组件中查询 规则如下&#xff1a; 使用如下&#xff1a; 如果在unicloud-db组件上不加判断条件&#xff0c;就会报错&#xff0c;并进入到登录页。 那么就会进入到登录页&#xff0c;加上了判断条件&#xff0c;有数据了就不会了。 因为在sc…

TQ15EG开发板教程:在MPSOC上运行ADRV9371(vivado2018.3)

首先需要在github上下载两个文件&#xff0c;本例程用到的文件以及最终文件我都会放在网盘里面&#xff0c; 地址放在本文最后。首先在github搜索hdl选择第一个&#xff0c;如下图所示 GitHub网址&#xff1a;https://github.com/analogdevicesinc/hdl/releases 点击releases…

【Maven工具】

maven Maven是一个主要用于Java项目的构建自动化工具。它有助于管理构建过程&#xff0c;包括编译源代码、运行测试、将编译后的代码打包成JAR文件以及管理依赖项。Maven使用项目对象模型&#xff08;POM&#xff09;文件来描述项目配置和依赖关系。 Maven通过提供标准的项目…

分布式系统中的唯一ID生成方法

通常在分布式系统中&#xff0c;有生成唯一ID的需求&#xff0c;唯一ID有多种实现方式。我们选择其中几种&#xff0c;简单阐述一下实现原理、适用场景、优缺点等信息。 目录 数据库多主复制UUID工单服务器雪花算法总结 数据库多主复制 数据库通常有自增属性&#xff0c;在单机…

解决vue启动项目报错:npm ERR! Missing script: “serve“【详细清晰版】

目录 问题描述问题分析和解决情况一解决方法情况二&#xff08;常见于vue3&#xff09;解决方法情况三解决方法 问题描述 在启动vue项目时通常在控制台输入npm run serve 但是此时出现如下报错&#xff1a; npm ERR! Missing script: "serve" npm ERR! npm ERR! T…

80% 的人都不会的 15 个 Linux 实用技巧

熟悉 Linux 系统的同学都知道&#xff0c;它高效主要体现在命令行。通过命令行&#xff0c;可以将很多简单的命令&#xff0c;通过自由的组合&#xff0c;得到非常强大的功能。 命令行也就意味着可以自动化&#xff0c;自动化会使你的工作更高效&#xff0c;释放很多手工操作&…

纸制品ERP怎么样

在纸制品行业中&#xff0c; ERP系统的应用已经成为提升企业竞争力的关键因素。本文将探讨万达宝ERP系统在制造成本控制、商品生命周期管理以及自动对接主流平台方面的作用&#xff0c;并分析其在业务流程优化、高效调节各类关系以及多种模式生产方面的特点和益处。 制造成本控…

【数据结构(六)】队列

❣博主主页: 33的博客❣ ▶️文章专栏分类:数据结构◀️ &#x1f69a;我的代码仓库: 33的代码仓库&#x1f69a; &#x1faf5;&#x1faf5;&#x1faf5;关注我带你学更多数据结构知识 目录 1.前言2.概念3.队列的使用4.循环队列5.双端队列6.经典习题6.1队列实现栈6.2栈实现队…

【学习笔记十】EWM自动产品包装配置

一、确定包装物料建议的程序 1.定义内向交货处理的凭证类型 2.确定包装物料建议的程序确定原理 使用可以确定包装材料建议的过程来指定业务代码。系统使用这些业务代码查找包装规格。包装期间&#xff0c;系统可建议包装材料。如果系统确定包装规格并建议包装材料&#xff0c;…

Maven创建项目

目录 1.创建项目 2.从Maven Repository: Search/Browse/Explore (mvnrepository.com)链接&#xff0c;下载API 3.1.0 3.在main文件内创建webapp文件夹&#xff0c;再webapp文件夹内创建WEB-INF文件夹&#xff0c;在WEB-INF文件夹内创建web.xml 4.网络编程 5.打包 6.部署 …

Python学习笔记16 - 函数

函数的创建和调用 函数调用的参数传递 函数的返回值 函数的参数定义 变量的作用域 递归函数 斐波那契数列 总结

网络编程套接字(二)之UDP服务器简单实现

目录 一、服务端UdpServer 1、udp_server.hpp 1、服务器的初始化 2、服务器的运行 2、udp_server.cc 二、客户端UdpClient udp_client.cc 三、完整代码 一、服务端UdpServer 1、udp_server.hpp 首先&#xff0c;我们在该文件中&#xff0c;将服务器封装成一个类&#…

网络抓包工具使用

一、下载安装 &#xff08;1&#xff09; linux&#xff1a; ① 使用 yum install tcpdump -y 安装 **tcpdump**工具 ② 编译安装 yum -y install gcc-c yum -y install flex yum -y install bison官网下载tcpdump和libpcap 官网地址:https://www.tcpdump.org/index.html#lat…

网红天水海英麻辣烫改名:还是商标的问题!

近日火爆网络的天水海英麻辣烫改名&#xff0c;改成“哈海英麻辣烫”&#xff0c;并打了TM&#xff0c;表示此商标名称商标局已经受理并下发通知书&#xff0c;普推知产老杨检索分析&#xff0c;改名的主要原因还是商标。 对于餐饮店和麻辣烫核心类别就在43类别及30类方便食品&…