k8s部署ingress-nginx

news2024/11/25 2:41:20

一、拉取ingress-nginx的安装代码
地址:https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.1/deploy/static/provider/cloud/deploy.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.11.1
  name: ingress-nginx
  namespace: ingress-nginx
---
apiVersion: v1
automountServiceAccountToken: true
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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  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.11.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  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: LoadBalancer
  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.11.1
  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.11.1
  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.11.1
    spec:
      containers:
      - args:
        - /nginx-ingress-controller
        - --publish-service=$(POD_NAMESPACE)/ingress-nginx-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.cn-hangzhou.aliyuncs.com/zhaoll/controller:v1.11.1
        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
      dnsPolicy: ClusterFirst
      nodeSelector:
        kubernetes.io/os: linux
      serviceAccountName: ingress-nginx
      terminationGracePeriodSeconds: 300
      volumes:
      - name: webhook-cert
        secret:
          secretName: ingress-nginx-admission
---
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.11.1
  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.11.1
      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.cn-hangzhou.aliyuncs.com/zhaoll/kube-webhook-certgen:v1.4.1
        imagePullPolicy: IfNotPresent
        name: create
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 65532
          seccompProfile:
            type: RuntimeDefault
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: OnFailure
      serviceAccountName: ingress-nginx-admission
---
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.11.1
  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.11.1
      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.cn-hangzhou.aliyuncs.com/zhaoll/kube-webhook-certgen:v1.4.1
        imagePullPolicy: IfNotPresent
        name: patch
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 65532
          seccompProfile:
            type: RuntimeDefault
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: OnFailure
      serviceAccountName: ingress-nginx-admission
---
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.11.1
  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.11.1
  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@master1 ~]# kubectl apply -f deploy.yaml 
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
serviceaccount/ingress-nginx-admission created
role.rbac.authorization.k8s.io/ingress-nginx created
role.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
configmap/ingress-nginx-controller created
service/ingress-nginx-controller created
service/ingress-nginx-controller-admission created
deployment.apps/ingress-nginx-controller created
job.batch/ingress-nginx-admission-create created
job.batch/ingress-nginx-admission-patch created
ingressclass.networking.k8s.io/nginx created
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created

安装好之后查看一下Pod和SVC的状态:

[root@master1 ~]# kubectl get svc,pod -n ingress-nginx -owide
NAME                                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE   SELECTOR
service/ingress-nginx-controller             NodePort    10.101.235.42    <none>        80:30080/TCP,443:30443/TCP   73s   app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/name=ingress-nginx
service/ingress-nginx-controller-admission   ClusterIP   10.100.197.238   <none>        443/TCP                      73s   app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-nginx,app.kubernetes.io/name=ingress-nginx

NAME                                            READY   STATUS      RESTARTS   AGE   IP               NODE      NOMINATED NODE   READINESS GATES
pod/ingress-nginx-admission-create-gmldg        0/1     Completed   0          72s   172.25.104.167   master2   <none>           <none>
pod/ingress-nginx-admission-patch-8dr6w         0/1     Completed   1          72s   172.21.11.37     node2     <none>           <none>
pod/ingress-nginx-controller-79dccb475b-vppll   1/1     Running     0          72s   172.21.11.38     node2     <none>           <none>

注意:ingress-nginx-controller的Pod为ingress-nginx-controller-79dccb475b-vppll,被调度在了node2节点上,我们后续访问ingress代理的服务,都要用node2节点的IP做DNS映射。且要记住http的端口是30080,https端口是30443,这两个端口都是我们在deploy.yaml中自定义的。

查看IngressClass:

[root@master1 ~]# kubectl get IngressClass
NAME    CONTROLLER             PARAMETERS   AGE
nginx   k8s.io/ingress-nginx   <none>       15m

记住上面这个IngressClass的名称为nginx,下一步要用到。

二、部署后端资源
我们打算使用3个nginx组成nginx-service,3个tomcat组成tomcat-service,然后创建一个ingress,用于代理tomcat和nginx的服务。配置如下:

# 部署3个nginx实例
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-pod
  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
      - name: nginx
        image: registry.cn-hangzhou.aliyuncs.com/zhaoll/nginx:1.27.0
        ports:
        - containerPort: 80
---
# 部署3个tomcat实例
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tomcat-pod
  template:
    metadata:
      labels:
        app: tomcat-pod
    spec:
      containers:
      - name: tomcat
        image: registry.cn-hangzhou.aliyuncs.com/zhaoll/tomcat:8.5-jre10-slim
        ports:
        - containerPort: 8080
---
# 部署nginx的Service
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx-pod
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
---
# 部署tomcat的Service
apiVersion: v1
kind: Service
metadata:
  name: tomcat-service
spec:
  selector:
    app: tomcat-pod
  type: ClusterIP
  ports:
  - port: 8080
    targetPort: 8080
---
# 创建ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-http
  #annotations:  
    #kubernetes.io/ingress.class: "nginx"  
spec:
  # 上面的IngressClass名称
  ingressClassName: "nginx"
  rules:
  # 域名,稍后要通过这个域名访问服务
  - host: nginx.itheima.com
    http:
      paths:
      # 路径,访问域名时后面添加的路径
      - path: /
        pathType: Prefix
        backend:
          # 要代理的服务和服务的端口
          service:
            name: nginx-service
            port: 
              number: 80
  - host: tomcat.itheima.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: tomcat-service
            port: 
              number: 8080

将上面的内容保存到demo.yaml文件中,并进行安装:

[root@master1 ~]# kubectl apply -f demo.yaml
[root@master1 ~]# kubectl get pod,svc,ingress
NAME                                          READY   STATUS    RESTARTS        AGE
pod/nginx-deployment-59c59966df-d5z5r         1/1     Running   0               22m
pod/nginx-deployment-59c59966df-hbh4j         1/1     Running   0               22m
pod/nginx-deployment-59c59966df-vwr5h         1/1     Running   0               22m
pod/tomcat-deployment-575d8857c7-6hqbh        1/1     Running   0               22m
pod/tomcat-deployment-575d8857c7-kktsw        1/1     Running   0               22m
pod/tomcat-deployment-575d8857c7-qjmgt        1/1     Running   0               22m

NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP    24d
service/nginx-service    ClusterIP   10.103.125.10   <none>        80/TCP     22m
service/tomcat-service   ClusterIP   10.104.88.147   <none>        8080/TCP   22m

NAME                                     CLASS   HOSTS                                  ADDRESS         PORTS   AGE
ingress.networking.k8s.io/ingress-http   nginx   nginx.itheima.com,tomcat.itheima.com   10.101.235.42   80      21m

查看一下ingress:

[root@master1 ~]# kubectl describe ingress ingress-http
Name:             ingress-http
Labels:           <none>
Namespace:        default
Address:          10.101.235.42
Ingress Class:    nginx
Default backend:  <default>
Rules:
  Host                Path  Backends
  ----                ----  --------
  nginx.itheima.com   /   nginx-service:80 (172.20.136.17:80,172.25.104.168:80,172.26.135.23:80)
  tomcat.itheima.com  /   tomcat-service:8080 (172.21.11.39:8080,172.25.104.169:8080,172.25.130.151:8080)
Events:
  Type    Reason  Age                From                      Message
  ----    ------  ----               ----                      -------
  Normal  Sync    22m (x2 over 23m)  nginx-ingress-controller  Scheduled for sync

从上面来看已经部署完成了,看一下ingress-nginx-controller的日志:

[root@master1 ~]# kubectl logs -f ingress-nginx-controller-79dccb475b-vppll -n ingress-nginx
W0813 14:34:47.144888       7 client_config.go:659] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0813 14:34:47.144993       7 main.go:205] "Creating API client" host="https://10.96.0.1:443"
-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       v1.11.1
  Build:         7c44f992012555ff7f4e47c08d7c542ca9b4b1f7
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.25.5

-------------------------------------------------------------------------------

I0813 14:34:47.148878       7 main.go:248] "Running in Kubernetes cluster" major="1" minor="30" git="v1.30.2" state="clean" commit="39683505b630ff2121012f3c5b16215a1449d5ed" platform="linux/amd64"
I0813 14:34:47.411837       7 main.go:101] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I0813 14:34:47.424942       7 ssl.go:535] "loading tls certificate" path="/usr/local/certificates/cert" key="/usr/local/certificates/key"
I0813 14:34:47.433034       7 nginx.go:271] "Starting NGINX Ingress controller"
I0813 14:34:47.440321       7 event.go:377] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"ingress-nginx", Name:"ingress-nginx-controller", UID:"14446290-d9d0-455b-8d9d-483a25436a65", APIVersion:"v1", ResourceVersion:"1672010", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap ingress-nginx/ingress-nginx-controller
I0813 14:34:48.634572       7 nginx.go:317] "Starting NGINX process"
I0813 14:34:48.634658       7 leaderelection.go:250] attempting to acquire leader lease ingress-nginx/ingress-nginx-leader...
I0813 14:34:48.635788       7 nginx.go:337] "Starting validation webhook" address=":8443" certPath="/usr/local/certificates/cert" keyPath="/usr/local/certificates/key"
I0813 14:34:48.635965       7 controller.go:193] "Configuration changes detected, backend reload required"
I0813 14:34:48.646166       7 leaderelection.go:260] successfully acquired lease ingress-nginx/ingress-nginx-leader
I0813 14:34:48.646453       7 status.go:85] "New leader elected" identity="ingress-nginx-controller-79dccb475b-vppll"
I0813 14:34:48.655622       7 controller.go:213] "Backend successfully reloaded"
I0813 14:34:48.655668       7 controller.go:224] "Initial sync, sleeping for 1 second"
I0813 14:34:48.655933       7 event.go:377] Event(v1.ObjectReference{Kind:"Pod", Namespace:"ingress-nginx", Name:"ingress-nginx-controller-79dccb475b-vppll", UID:"2c60e3d9-bdaf-4c90-a7f2-090eb72c74ab", APIVersion:"v1", ResourceVersion:"1672069", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I0813 14:35:14.884334       7 main.go:107] "successfully validated configuration, accepting" ingress="default/ingress-http"
I0813 14:35:14.888599       7 store.go:440] "Found valid IngressClass" ingress="default/ingress-http" ingressclass="nginx"
I0813 14:35:14.888923       7 event.go:377] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"ingress-http", UID:"8548894c-bbd9-4100-9e78-8a803d42385b", APIVersion:"networking.k8s.io/v1", ResourceVersion:"1672337", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
I0813 14:35:16.341450       7 controller.go:193] "Configuration changes detected, backend reload required"
I0813 14:35:16.363364       7 controller.go:213] "Backend successfully reloaded"
I0813 14:35:16.363926       7 event.go:377] Event(v1.ObjectReference{Kind:"Pod", Namespace:"ingress-nginx", Name:"ingress-nginx-controller-79dccb475b-vppll", UID:"2c60e3d9-bdaf-4c90-a7f2-090eb72c74ab", APIVersion:"v1", ResourceVersion:"1672069", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I0813 14:35:48.652255       7 status.go:304] "updating Ingress status" namespace="default" ingress="ingress-http" currentValue=null newValue=[{"ip":"10.101.235.42"}]
I0813 14:35:48.656752       7 event.go:377] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"ingress-http", UID:"8548894c-bbd9-4100-9e78-8a803d42385b", APIVersion:"networking.k8s.io/v1", ResourceVersion:"1672462", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync

从最后几条日志来看,我们创建的ingress已经与ingress-nginx成功关联上了,下面可以进行访问测试了。

三、访问测试
在Windows电脑的HOSTS文件里添加两行配置:

11.0.1.105 nginx.itheima.com
11.0.1.105 tomcat.itheima.com

这个11.0.1.105是你ingress-nginx-controller的Pod所在k8s节点的地址,这点需要记清楚了。
浏览器访问测试:nginx.itheima.com:30080
在这里插入图片描述
浏览器访问测试:tomcat.itheima.com:30080
在这里插入图片描述
访问成功,配置完成了。

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Keepalived详解

目录 1、高可用集群keepalived 高可用集群 VRRP 相关概念 keepalived 简介 2、基础实验环境搭建 3、keepalived的虚拟路由管理 全局配置 ​编辑 配置虚拟路由器 4、虚拟路由的通讯设置 5、keepalived的日志分离 6、实现独立子配置文件 7、keepalived的抢占模式和非抢占…

ubuntu 20 安装mysql workbench 过程

ubuntu 20 安装mysql workbench 过程_ubuntu 安装mysql workbench-CSDN博客 How To Install And Use MySQL Workbench On Ubuntu 18.04 or 20.04 MySQL :: Begin Your Download sudo apt install ./mysql-apt-config_0.8.32-1_all.deb snap install mysql-workbench-communi…

【鸿蒙学习】HarmonyOS应用开发者基础 - 从简单的页面开始

学完时间&#xff1a;2024年8月13日 我的纸飞机呀&#xff01;飞呀飞&#xff01;飞到了代码中&#xff01;&#xff01;&#xff01; 一、前言叨叨 今天是HarmonyOS学习教学课第一课的第五课内容了&#xff0c;课后练习的人数已经降到了4150人了&#xff0c;预测下到 ”Harmon…

Win10 去掉桌面右上角 了解有关此图片的信息

1. 进入注册表 Win R运行regedit 2. 找到以下路径 计算机\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel 3. 新建 DWORD&#xff08;32位&#xff09;值&#xff08;D&#xff09; 右击 NewStartPanel新建 DWORD…

前端技术day01-HTML入门

一、前端介绍 技术描述HTML用于构建网站的基础结构的CSS用于美化页面的&#xff0c;作用和化妆或者整容作用一样JS实现网页和用户的交互Vue主要用于将数据填充到html页面上的Element主要提供了一些非常美观的组件 二、工具软件 VsCode 在前端领域&#xff0c;有一个公认好用…

C语言问答进阶--6、函数(1)

A&#xff1a;现在我们将研究函数这个概念。 其实这个概念很简单&#xff0c;和中学的时候学的yf(x)来对照着看&#xff0c;对于一个参数x&#xff0c;会得到一个值y&#xff0c;就会发现它和C中的函数是一个道理。 只是C函数中可以包含不传入任何参数的函数。 A&#xff1a;函…

自学嵌入式第十九天高级编程篇 文件2

标准IO的返回值判断 feof&#xff1a;判断文件流指针是否到达结尾。 feof(src) //如果文件流指针到达末尾&#xff0c;函数返回值为真 ferror&#xff1a;判断文件流指针是否出错。搭配clearerr使用可以跳过报错的地方&#xff0c;读取后面的数据 ferror(src) //如…

短视频SDK解决方案,良好的二次开发可扩展性

短视频已成为当代社交与内容消费的重要载体&#xff0c;其影响力与日俱增&#xff0c;面对这一蓬勃发展的市场&#xff0c;如何高效、创新地打造短视频应用&#xff0c;成为众多开发者和企业的核心关切。在此背景下&#xff0c;美摄科技凭借其深厚的技术积累与前瞻性的市场洞察…

奇异值分解(SVD)

1 奇异值分解(SVD)简介 Beltrami 和 Jordan 被认为是奇异值分解&#xff08;Singular Value Decomposition&#xff0c;SVD&#xff09;的共同开创者&#xff0c;二人于19世纪70年代相继提出了相关理论。奇异值分解主要解决的问题是数据降维。在高维度的数据中&#xff0c;数据…

什么是流批一体?怎样理解流批一体?

目录 一、流式处理与批量处理概述 1.流式处理 2.批量处理 3.流批一体的定义 二、流批一体的关键特点 三、流批一体的技术实现 四、应用场景 五、实施流批一体的考虑因素 流批一体听起来很简单&#xff0c;但内涵却十分复杂。它包含了计算语义、编程模型、API、调度、执行、shuf…

Halcon玩转机器视觉专栏特殊声明

欢迎来到 PaQiuQiu 的空间 本文为【Halcon玩转机器视觉专栏特殊声明】&#xff0c;方便大家更合理的订阅! &#x1f4e2; ~特殊声明~ 鉴于很多童鞋在订阅专栏过程中&#xff0c;对于专栏中涉及到的资料&#xff08;比如中文学习手册&#xff09;和源码&#xff08;C#联合Halco…

背包九讲(动态规划)

文章目录 01背包问题题目描述解题思路&#xff1a;上代码&#xff1a;思路2&#xff1a;二维代码&#xff1a;优化代码&#xff1a; 完全背包问题题目描述&#xff1a;解题思路&#xff1a;二维代码&#xff1a;优化代码&#xff1a; 多重背包问题题目描述&#xff1a;解题思路…

有趣的rce漏洞复现分析(1)

目录 eval长度限制突破 第一种方法 第二种方法 无字母数字webshell之命令执行 php7 php5 eval长度限制突破 php eval函数参数限制在16个字符的情况下&#xff0c;如何拿到webshell呢 首先&#xff0c;我们还是先把环境搭好&#xff08;此次的所有漏洞环境我都部署在Ubu…

MySQL的索引事务和JDBC编程

目录 索引 查看索引 创建索引 删除索引 底层数据结构&#xff08;这个很重要哦&#xff0c;面试容易问&#xff09; 事务 事务的使用 事务的基本特性 并发执行事务可能产生的问题 MySQL提供的四种事务隔离级别 JDBC编程 JDBC的来源&#xff08;一定要了解&#xff…

[WUSTCTF2020]颜值成绩查询

打开题目 输入1 输出 输入1会提示学号不存在 输入1/**/or/**/11#,过滤了空格。 1/**/order/**/by/**/3# 存在 1/**/order/**/by/**/4# 不存在 绕过 爆破表名 -1/**/Union/**/Select/**/1,2,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/tabl…

8.1.数据库基础技术-数据库基本概念

数据库基本概念 数据库系统概述三级模式两级映射概念模式内模式外模式三级模式两级映像练习题 数据库设计练习题 数据库系统概述 数据&#xff1a;是数据库中存储的基本对象&#xff0c;是描述事物的符号记录。 数据的分类&#xff1a;文本、图形、图像、音频、视频。 数据库…

Unity动画模块 之 2D IK(反向动力学)

本文仅作笔记学习和分享&#xff0c;不用做任何商业用途 本文包括但不限于unity官方手册&#xff0c;unity唐老狮等教程知识&#xff0c;如有不足还请斧正​ 1.什么是IK 反向动力学 IK&#xff08;Inverse Kinematics&#xff09;是一种方法&#xff0c;可以根据某些子关节的最…

C++初阶:内存管理详解

✨✨小新课堂开课了&#xff0c;欢迎欢迎~✨✨ &#x1f388;&#x1f388;养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; 所属专栏&#xff1a;C&#xff1a;由浅入深篇 小新的主页&#xff1a;编程版小新-CSDN博客 1.C/C内存分布 我们先来看下面一段代码和相…

Haproxy简介及配置详解

一、Haproxy简介 官网&#xff1a; 企业版网站: https://www.haproxy.com 社区版网站: http://www.haproxy.org github: https://github.com/haprox Haproxy是法国人Willy Tarreaus开发的一款开源软件&#xff0c;能够提供高性能、负载均衡以及基于HTTP和TCP应用个代理&…

微信自动回复的设置

如何在微信上高效回复客户&#xff0c;提供良好的用户体验是很重要的。 但常常因为一人管理太多号&#xff0c;消息回复不过来&#xff1b;同时太多客户咨询&#xff0c;手忙脚乱&#xff1b;回复的话术让人感到不专业。 没关系&#xff0c;小编有办法。给大家分享几个小技巧…