|NO.Z.00351|——————————|CloudNative|——|KuberNetes&运维.V67|——|IngressNginx.v03|域名重定向.v01|

一、IngressNginx概述
### --- IngressNginx重定向:域名重定向到另外一个域名

~~~     # 实例一:http转成https会使用到
~~~     # 实例二:新旧域名的替换会使用到
二、创建IngressNginx容器
### --- 创建nginx.deployment.yaml文件
~~~     创建nginx-deployment

[root@k8s-master01 IngressNginx]# vim nginx-deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: {}
  labels:
    app: ingress-test
  name: ingress-test
  namespace: ratel-test1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ingress-test
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: ingress-test
    spec:
      affinity: {}
      containers:
      - env:
        - name: TZ
          value: Asia/Shanghai
        - name: LANG
          value: C.UTF-8
        image: nginx
        imagePullPolicy: IfNotPresent
        lifecycle: {}
        name: ingress-test
        ports:
        - containerPort: 80
          name: web
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 10m
            memory: 10Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/zoneinfo/Asia/Shanghai
          name: tz-config
        - mountPath: /etc/localtime
          name: tz-config
        - mountPath: /etc/timezone
          name: timezone
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
          type: ""
        name: tz-config
      - hostPath:
          path: /etc/timezone
          type: ""
        name: timezone
三、创建nginx-deployment
### --- 创建nginx-deployment

[root@k8s-master01 IngressNginx]# kubectl create -f nginx-deployment.yaml
### --- 查看创建的po、svc、ep

[root@k8s-master01 IngressNginx]# kubectl get po,svc,ep -n ratel-test1 -owide
NAME                                READY   STATUS    RESTARTS   AGE     IP               NODE           NOMINATED NODE   READINESS GATES
pod/ingress-test-6dd476fb56-twrdf   1/1     Running   0          8m24s   172.25.244.203   k8s-master01   <none>           <none>

NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE     SELECTOR
service/ingress-test   ClusterIP   10.106.126.20   <none>        80/TCP    8m24s   app=ingress-test

NAME                     ENDPOINTS           AGE
endpoints/ingress-test   172.25.244.203:80   8m24s
 ### --- 验证通过service访问nginx
 
[root@k8s-master01 IngressNginx]# curl 10.106.126.20 
<h1>Welcome to nginx!</h1>
四、创建一个nginx-ingress
### --- 创建nginx-ingress-demo.yaml文件

[root@k8s-master01 IngressNginx]#  vim nginx-ingress-demo.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:       
  name: ingress-test
  namespace: ratel-test1
spec:
  rules:
  - host: ingress.test.com
    http:
      paths:
      - backend:
          serviceName: ingress-test
          servicePort: 80
        path: /
### --- 创建nginx-ingress-demo

[root@k8s-master01 IngressNginx]# kubectl create -f nginx-ingress-demo.yaml 
ingress.extensions/ingress-test created
### --- 配置本地hosts文件
~~~     配置hosts,把域名直接指到ingress服务器上,
~~~     但是生产环境中,是不建议这样使用的,因为生产服务器是不会直接暴露在公网上面的
~~~     一般都是域名厂商把域名解析到外部的SLB或者外部的负载均衡上,然后负载均衡再到服务上

192.168.1.11 ingress.test.com
五、通过域名访问nginx.pod :地址:http://ingress.test.com/

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(28)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示