项目实战:Ingress搭建Nginx+WP论坛+MariaDB

news2024/11/16 21:25:44

1. 网站架构


本次部署形式完全舍弃 Docker,将所有应用都置于Kubernetes,采用 Deployment 而非单 Pod 部署,稳定性得到升级。

2. 部署 MariaDB

[root@k8s-master ~]# mkdir tdr
[root@k8s-master ~]# cd tdr/

(1)定义 ConfigMap

[root@k8s-master tdr]# vim mariadb-configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
        name: mariadb-configmap
data:
        USER: "wp"
        PASSWORD: "123"
        ROOT_PASSWORD: "123"
        DATABASE: "db"

(2)定义 Deployment

[root@k8s-master tdr]# vim mariadb-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
        name: mariadb-deployment
        labels:
                app: mariadb-deployment
spec:
        replicas:
        selector: 
                matchLabels:
                        app: mariadb-deployment
        template:
                metadata: 
                        labels:
                                app: mariadb-deployment
                spec:
                        containers:
                        -       name: mariadb
                                image: docker.io/library/mariadb:latest
                                imagePullPolicy: Never
                                ports:
                                -       name: mariadbport
                                        containerPort: 3306
                                envFrom:
                                -       prefix: "MARIADB_"
                                        configMapRef:
                                                name: mariadb-configmap

(3)定义 Service

[root@k8s-master tdr]# vim mariadb-service.yaml 
apiVersion: v1
kind: Service
metadata:
        name: mariadb-service
spec:
        selector:
                app: mariadb-deployment
        ports:
        -       port: 3306
                targetPort: 3306
                protocol: TCP
        type: NodePort

(4)启动 MariaDB

[root@k8s-master tdr]# kubectl create -f mariadb-configmap.yaml 
configmap/mariadb-configmap created
[root@k8s-master tdr]# kubectl create -f mariadb-deployment.yaml 
deployment.apps/mariadb-deployment created
[root@k8s-master tdr]# kubectl create -f mariadb-service.yaml 
service/mariadb-service created

[root@k8s-master tdr]# kubectl get all
NAME                                      READY   STATUS    RESTARTS       AGE
#pod信息:
pod/cluster-test-66bb44bd88-nk46t         1/1     Running   38 (14m ago)   10d
pod/mariadb-deployment-5bf6d9f98c-wt7cc   1/1     Running   0              25m
#service信息:
NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
service/kubernetes        ClusterIP   10.96.0.1      <none>        443/TCP          10d
service/mariadb-service   NodePort    10.96.249.62   <none>        3306:30150/TCP   14m
#deployment信息:
NAME                                 READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/cluster-test         1/1     1            1           10d
deployment.apps/mariadb-deployment   1/1     1            1           25m
#replicaset信息:
NAME                                            DESIRED   CURRENT   READY   AGE
replicaset.apps/cluster-test-66bb44bd88         1         1         1       10d
replicaset.apps/mariadb-deployment-5bf6d9f98c   1         1         1       25m

[root@k8s-master tdr]# kubectl exec -it pods/cluster-test-66bb44bd88-nk46t -- bash
(08:47 cluster-test-66bb44bd88-nk46t:/) nslookup mariadb-service
Server:        10.96.0.10
Address:    10.96.0.10#53

Name:    mariadb-service.default.svc.cluster.local
Address: 10.96.249.62

3. 部署 Wrodpress

(1)定义 ConfigMap

[root@k8s-master tdr]# vim wordpress-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
        name: wordpress-config
data:
        NAME: "db"
        USER: "wp"
        PASSWORD: "123"
        HOST: "mariadb-service"

(2)定义 Deployment

[root@k8s-master tdr]# vim wordpress-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
        name: wordpress-deployment
        labels:
                app: wordpress-deployment
spec:
        replicas: 2
        selector:
                matchLabels:
                        app: wordpress-deployment
        template:
                metadata:
                        labels:
                                app: wordpress-deployment
                spec:
                        containers:
                        -       name: wp
                                image: docker.io/library/wordpress:latest
                                imagePullPolicy: Never
                                ports:
                                -       name: wordpressport
                                        containerPort: 80
                                envFrom:
                                -       prefix: "WORDPRESS_DB_"
                                        configMapRef:
                                                name: wordpress-config

(3)定义 Service

[root@k8s-master tdr]# vim wordpress-service.yaml 
apiVersion: v1
kind: Service
metadata:
        name: wordpress-service
spec:
        selector:
                app: wordpress-deployment
        ports:
        -       name: http
                port: 80
                targetPort: 80
                protocol: TCP
                nodePort: 32000
        type: NodePort

(4)启动 WordPress

[root@k8s-master tdr]# kubectl create -f wordpress-configmap.yaml 
configmap/workpress-config created
[root@k8s-master tdr]# kubectl create -f wordpress-deployment.yaml
deployment.apps/wordpress-deployment created
[root@k8s-master tdr]# kubectl create -f wordpress-service.yaml 
service/wordpress-service created
[root@k8s-master tdr]# kubectl get po
NAME                                    READY   STATUS    RESTARTS       AGE
cluster-test-66bb44bd88-nk46t           1/1     Running   38 (50m ago)   10d
mariadb-deployment-5bf6d9f98c-wt7cc     1/1     Running   0              60m
wordpress-deployment-555685954b-77wb8   1/1     Running   0              107s
wordpress-deployment-555685954b-9g8rf   1/1     Running   0              107s

(5)访问测试

访问192.168.1.110:32000

4. 部署Nginx Ingress Controller

(1)安装Ingress Controller

https://www.yuque.com/login?goto=https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2024%2Fyaml%2F27632550%2F1704426623262-496917bf-7f4b-48e6-83e1-429f2e1ee853.yaml
下载附件再导入到服务器内,再进行安装

[root@k8s-master tdr]# cat ingress.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.7.1
  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.7.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.7.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.7.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.7.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.7.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.7.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.7.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.7.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.7.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: "true"
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.7.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.7.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  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.7.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.7.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
  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.7.1
    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
        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-beijing.aliyuncs.com/dotbalo/ingress-nginx-controller:v1.7.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: true
          capabilities:
            add:
            - NET_BIND_SERVICE
            drop:
            - ALL
          runAsUser: 101
        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.7.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.7.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-beijing.aliyuncs.com/dotbalo/kube-webhook-certgen:v20230312
        imagePullPolicy: IfNotPresent
        name: create
        securityContext:
          allowPrivilegeEscalation: false
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: OnFailure
      securityContext:
        fsGroup: 2000
        runAsNonRoot: true
        runAsUser: 2000
      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.7.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.7.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-beijing.aliyuncs.com/dotbalo/kube-webhook-certgen:v20230312
        imagePullPolicy: IfNotPresent
        name: patch
        securityContext:
          allowPrivilegeEscalation: false
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: OnFailure
      securityContext:
        fsGroup: 2000
        runAsNonRoot: true
        runAsUser: 2000
      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.7.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.7.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@k8s-master tdr]# kubectl create -f ingress.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

[root@k8s-master tdr]# kubectl get po -n ingress-nginx 
NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-mxff4        0/1     Completed   0          13m
ingress-nginx-admission-patch-lbmck         0/1     Completed   2          13m
ingress-nginx-controller-674f66cf96-xjs2t   1/1     Running     0          13m

[root@k8s-master ~]# kubectl get svc -n ingress-nginx 
NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             NodePort    10.96.184.233   <none>        80:31546/TCP,443:31757/TCP   14m
ingress-nginx-controller-admission   ClusterIP   10.96.243.95    <none>        443/TCP   
#记住ingress-nginx-controller的端口映射80=>31546

(2)部署Ingress

在安装本文的Ingress时,Ingress class已连带被定义,所以直接部署 Ingress

[root@k8s-master tdr]# kubectl get ingressclasses.networking.k8s.io 
NAME    CONTROLLER             PARAMETERS   AGE
nginx   k8s.io/ingress-nginx   <none>       29m

[root@k8s-master tdr]# vim web-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
        name: nginx-ingress
spec:
        ingressClassName: nginx
        rules:
        -       host: wp-web.com          #域名
                http:
                        paths:
                        -       backend:
                                        service:
                                                name: wordpress-service           #service名称,这里要匹配到wordpress的service
                                                port:
                                                        number: 80
                                path: /
                                pathType: ImplementationSpecific         #路径匹配方式


[root@k8s-master tdr]# kubectl create -f web-ingress.yaml 
ingress.networking.k8s.io/nginx-ingress created

5. 访问测试

(1)主机hosts劫持

修改 windows 映射文件:C:\Windows\System32\drivers\etc

找到 hosts 文件,使用记事本打开,编辑最后的内容

(2)测试访问IP

访问 IP+Ingress 映射的端口是无法进入后端服务器的

(3)测试访问 URL

只有访问先前定义的域名+端口才可访问到后端服务器
本次实战域名服务器为:wp-web.com:31546
后续论坛网站自行搭建

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

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

相关文章

再也不怕数据丢失!四款数据恢复免费软件分享!

在数据满天飞的今天&#xff0c;一不小心就可能遭遇数据丢失的“惊魂一刻”。虽然数据丢失几乎是大家遇到过的事情&#xff0c;不仅仅是数据被删除&#xff0c;也可能是因为一些小意外。不过别担心&#xff0c;今天就来聊聊四位数据恢复界的“护法”&#xff0c;看看它们在实战…

PostgreSQL 创建表,常规表、外部表、分区表区别讲解

PostgreSQL 创建表&#xff0c;常规表、外部表、分区表区别讲解 创建表&#xff0c;常规表、外部表、分区表区一、常规表1. 定义和特点&#xff1a;2. 适用场景&#xff1a; 二、外部表1. 定义和特点&#xff1a;2. 适用场景&#xff1a; 三、分区表1. 定义和特点&#xff1a;2…

quiz: python网络爬虫之规则1

下面答错了&#xff1a; B c 8A&#xff0c; 9A

代码随想录算法训练营第四十三天 | 300.最长递增子序列,674. 最长连续递增序列,718. 最长重复子数组

四十三天打卡&#xff0c;今天解决子序列系列题目&#xff0c;定义dp[i]为以nums[i]为结尾的最长子序列长度。 300.最长递增子序列 题目链接 2024.7.12一刷 没做出来。这题答案使用dp做&#xff0c;答案也不是dp.back()&#xff0c;思路需要转换一下。 2024.9.27二刷 解题…

酒店智能门锁接口pro[V10] 对接酒店收银-SAAS本地化-未来之窗行业应用跨平台架构

一、文档 调用函数库&#xff1a; 提供Windows下的32位动态连接库proRFL.DLL&#xff0c;函数使用详细说明 //-----------------------------------------------------------------------------------// 功能&#xff1a;读DLL版本&#xff0c;不涉及USB口操作 C原型&…

Unity八股总结

这里写目录标题 OnEnable、Awake、Start运行时的发生顺序&#xff1f;哪些可能在同一个对象周期中反复的发生&#xff1f;动态加载资源的方式?Unity3d脚本从唤醒到销毁有着一套比较完整的生命周期&#xff0c;请列出系统自带的几个重要的方法。物理更新一般放在哪个系统函数里…

视频加字幕软件:5款好用加字幕软件来袭!

在视频制作过程中&#xff0c;添加字幕不仅能够提升观众的观看体验&#xff0c;还能有效传达视频信息&#xff0c;增强内容的吸引力和理解度。然而&#xff0c;市面上众多的视频加字幕软件让人眼花缭乱&#xff0c;不知如何选择。今天&#xff0c;我们就来盘点五款既实用又易上…

设计模式之享元(Flyweight)模式

前言 面向对象很好地解决了 “抽象” 的问题&#xff0c;但是不可避免的要付出一定的代价。对于通常情况来讲&#xff0c;面向对象的成本大都可以忽略不计。但是某些情况&#xff0c;面向对象所带来的成本必须谨慎处理 具体需要自己根据需求去评估 定义 “对象性能” 模式。运用…

pdf转ppt文件有哪些方法?这几种方法看了就能学会!

pdf转ppt文件有哪些方法&#xff1f;PDF与PPT&#xff0c;作为两种广泛应用的文件格式&#xff0c;它们各自承载着不同的功能特性与适用场景&#xff0c;其间的差异远不止于表面&#xff0c;首先&#xff0c;PDF可以很好的保留文档原始布局与内容&#xff0c;它确保了信息的精确…

【记录】在返回值类型为BigDecimal情况下末尾小数位为0的会省略不显示

【问题】&#xff1a;在返回值类型为BigDecimal情况下末尾小数位为0的会省略不显示 问题复现&#xff1a; 实体类 package com.zlp.aspect.entity;import java.math.BigDecimal;/*** program: my_utils* description:* author: zlp* create: 2024-09-24 10:01**/public clas…

【test】google cloud

https://shell.cloud.google.com/ 默认已经安装了 VsCode 开发环境和终端界面&#xff0c;都是在线运行的&#xff0c;使用非常丝滑。 此外&#xff0c;服务器上还默认安装了 Docker, 这样就可以直接在 Docker 基础上运行一个 Kubernetes 本地集群了&#xff0c;还要啥自行车…

经典单方程计量经济学模型:一元线性回归模型-Eviews实现

下表为中国内地某年各地区税收Y与国内生产总值的GDP的统计资料。 地区YGDP 北京1435.79353.3 天津438.45050.4 河北618.313709.5 山西430.55733.4内蒙古347.96091.1 辽宁815.711023.5 吉林237.45284.7黑龙江3357065 上海1975.512188.9 江苏1894.825741.2 浙江1535.418780.4 安…

剖解环形链表1

环形链表 思路&#xff1a;我们知道在操场上跑步&#xff0c;若一个人跑的快&#xff0c;另一个人跑得慢&#xff0c;那么就一定会有相遇的那一刻&#xff0c;两人站在同一个位置&#xff0c;所以我们可以分别定义快慢指针&#xff0c;若快指针和慢指针相逢&#xff0c;就说明该…

梦幻西游端游如何查看挂机进度,GameViewer远程随时手机畅玩梦幻西游

原来用手机就可以免费玩梦幻西游端游&#xff1f;还可以随时查看游戏进度&#xff01;如果你喜欢玩梦幻西游端游&#xff0c;有总觉得出门在外不方面携带电脑&#xff0c;要想用手机实现随时随地查看梦幻西游的挂机进度&#xff0c;可以用网易GameViewer远程这款专为游戏玩家设…

望繁信科技携手甫瀚咨询共建流程挖掘产业生态

2023年&#xff0c;望繁信科技与甫瀚咨询达成战略合作并签署生态伙伴合作协议。双方将携手共同探索流程挖掘在各领域企业的应用场景&#xff0c;提供更全面及高效的流程挖掘解决方案&#xff0c;以助力企业在数字化转型浪潮中实现精益管理。 自2009年起&#xff0c;流程挖掘从…

深度学习:迁移学习

目录 一、迁移学习 1.什么是迁移学习 2.迁移学习的步骤 1、选择预训练的模型和适当的层 2、冻结预训练模型的参数 3、在新数据集上训练新增加的层 4、微调预训练模型的层 5、评估和测试 二、迁移学习实例 1.导入模型 2.冻结模型参数 3.修改参数 4.创建类&#xff…

windows 录音编码为flv格式时,pcm采样格式

这里使用的是0x3e&#xff0c;转换为二进制&#xff1a; 0 0 1 1 1 1 1 0 前四个字节为3&#xff0c;表示Linear Pcm, 后4个字节1 1 1 0 表示44100HZ采样&#xff0c; 16个bit&#xff0c;单声道。 故&#xff0c;windows 音频采样不支持48000HZ频率

基于Hive和Hadoop的电商消费分析系统

本项目是一个基于大数据技术的电商消费分析系统&#xff0c;旨在为用户提供全面的电商消费信息和深入的消费行为分析。系统采用 Hadoop 平台进行大规模数据存储和处理&#xff0c;利用 MapReduce 进行数据分析和处理&#xff0c;通过 Sqoop 实现数据的导入导出&#xff0c;以 S…

QT 获取视频帧Opencv获取清晰度

先展示结果&#xff1a; 1.获取摄像头的分辨率 mResSize.clear();mResSize camera_->supportedViewfinderResolutions();ui->comboBox_resulation->clear();int i0;foreach (QSize msize, mResSize) {qDebug()<<msize;ui->comboBox_resulation->addItem(…

9.27作业

顺序表 SeqList.h #ifndef SEQLIST_H #define SEQLIST_H #include <iostream> #include<memory.h> #include<stdlib.h> #include<string.h> using namespace std;//封装一个顺序表 template <typename T> class SeqList { private:T *ptr; …