[单master节点k8s部署]35.ingress 反向代理(二)

成功部署ingress controller

[root@master 35ingress]# kubectl get pods -n kube-system
NAME                                        READY   STATUS    RESTARTS         AGE
calico-kube-controllers-7dc5458bc6-fpv96    1/1     Running   10 (4d16h ago)   9d
calico-node-d9492                           1/1     Running   5 (4d1h ago)     9d
calico-node-nlfph                           1/1     Running   5 (4d16h ago)    9d
calico-node-z8zmg                           1/1     Running   4 (4d2h ago)     9d
coredns-7c445c467-k8vtx                     1/1     Running   5 (4d16h ago)    9d
coredns-7c445c467-rm98p                     1/1     Running   5 (4d16h ago)    9d
default-http-backend-96868495f-dc6mw        1/1     Running   0                4d
etcd-master                                 1/1     Running   5 (4d16h ago)    9d
kube-apiserver-master                       1/1     Running   5 (4d16h ago)    9d
kube-controller-manager-master              1/1     Running   15 (4d16h ago)   9d
kube-proxy-6szdl                            1/1     Running   5 (4d2h ago)     9d
kube-proxy-jpkgj                            1/1     Running   5 (4d16h ago)    9d
kube-proxy-zm7gh                            1/1     Running   5 (4d1h ago)     9d
kube-scheduler-master                       1/1     Running   15 (4d16h ago)   9d
kube-state-metrics-66b85747b7-4bqmn         1/1     Running   0                4d2h
monitoring-grafana30-5785b5b69-gch55        1/1     Running   0                4d2h
nginx-ingress-controller-67685fb594-khhs6   1/1     Running   0                31s
[root@master 35ingress]# kubectl logs nginx-ingress-controller-67685fb594-khhs6 -n kube-system
-------------------------------------------------------------------------------
NGINX Ingress controllerRelease:       v1.9.5Build:         f503c4bb5fa7d857ad29e94970eb550c2bc00b7cRepository:    https://github.com/kubernetes/ingress-nginxnginx version: nginx/1.21.6-------------------------------------------------------------------------------W1011 05:04:31.470197       7 client_config.go:618] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I1011 05:04:31.470499       7 main.go:205] "Creating API client" host="https://10.96.0.1:443"
I1011 05:04:31.478962       7 main.go:249] "Running in Kubernetes cluster" major="1" minor="30" git="v1.30.0" state="clean" commit="7c48c2bd72b9bf5c44d21d7338cc7bea77d0ad2a" platform="linux/amd64"
I1011 05:04:31.481068       7 main.go:83] "Valid default backend" service="kube-system/default-http-backend"
I1011 05:04:31.623444       7 main.go:101] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I1011 05:04:31.650576       7 nginx.go:260] "Starting NGINX Ingress controller"
I1011 05:04:31.660913       7 event.go:298] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"kube-system", Name:"nginx-configuration", UID:"11b6a56f-d772-4ae6-8838-233241499e0a", APIVersion:"v1", ResourceVersion:"1606978", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap kube-system/nginx-configuration
I1011 05:04:32.755601       7 store.go:440] "Found valid IngressClass" ingress="default/ingress-myapp" ingressclass="nginx"
I1011 05:04:32.755918       7 event.go:298] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"ingress-myapp", UID:"1e7137d2-cfc2-4968-8486-39fe0e9329bf", APIVersion:"networking.k8s.io/v1", ResourceVersion:"1608405", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
I1011 05:04:32.853228       7 nginx.go:303] "Starting NGINX process"
I1011 05:04:32.853351       7 leaderelection.go:245] attempting to acquire leader lease kube-system/ingress-controller-leader...
I1011 05:04:32.854105       7 controller.go:190] "Configuration changes detected, backend reload required"
I1011 05:04:32.856566       7 status.go:84] "New leader elected" identity="nginx-ingress-controller-5959964446-shz2n"
I1011 05:04:32.933605       7 controller.go:210] "Backend successfully reloaded"
I1011 05:04:32.933748       7 controller.go:221] "Initial sync, sleeping for 1 second"
I1011 05:04:32.933849       7 event.go:298] Event(v1.ObjectReference{Kind:"Pod", Namespace:"kube-system", Name:"nginx-ingress-controller-67685fb594-khhs6", UID:"b9bb377b-f407-4623-8586-a118a12cb779", APIVersion:"v1", ResourceVersion:"1608901", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I1011 05:05:13.817828       7 leaderelection.go:255] successfully acquired lease kube-system/ingress-controller-leader
I1011 05:05:13.817979       7 status.go:84] "New leader elected" identity="nginx-ingress-controller-67685fb594-khhs6"
I1011 05:05:13.825218       7 status.go:304] "updating Ingress status" namespace="default" ingress="ingress-myapp" currentValue=null newValue=[{"ip":"192.168.244.129"}]
I1011 05:05:13.829589       7 event.go:298] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"ingress-myapp", UID:"1e7137d2-cfc2-4968-8486-39fe0e9329bf", APIVersion:"networking.k8s.io/v1", ResourceVersion:"1609024", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync

成功部署default backend 

[root@master 35ingress]# kubectl get svc -n kube-system
NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                  AGE
default-http-backend   ClusterIP   10.103.76.255   <none>        80/TCP                   4d
kube-dns               ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP   9d
kube-state-metrics     ClusterIP   10.108.120.73   <none>        8080/TCP                 9d
monitoring-grafana     NodePort    10.96.63.74     <none>        80:32555/TCP             9d

部署一个后端tomcat服务

这个tomcat将由nginx-ingress-contoller代理,我们在这里通过tomcat服务来测试反向代理。可以看到这个tomcat包括两个pods和一个服务。

apiVersion: v1
kind: Service
metadata:name: tomcat-svc35
spec:selector:app: tomcatrelease: canaryports:- name: httptargetPort: 8080port: 8080- name: ajpport: 8009targetPort: 8009
---
apiVersion: apps/v1
kind: Deployment
metadata:name: tomcat
spec:replicas: 2selector:matchLabels:app: tomcatrelease: canarytemplate:metadata: labels:app: tomcatrelease: canaryspec:containers:- name: tomcatimage: docker.io/tomcat:8.5-jdk8 imagePullPolicy: Neverports:- name: httpcontainerPort: 8080- name: ajpcontainerPort: 8009

部署ingress

这个ingress就是引导nginx-ingress-controller与部署的tomcat服务之间的一个连接。这里的host是可以自己定义的,后续对tomcat服务的访问将通过这个host 名称。

[root@master 35ingress]# cat ingress-myapp.yaml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: ingress-myappannotations:ingressClassName: "nginx"
spec:rules:- host: tomcat.lucky.comhttp:paths:- path: /pathType: Prefixbackend:service:name: tomcat-svc35port: number: 8080

得到一个ingress资源,host为tomcat.lucky.com,是一个nginx ingress资源。

[root@master 35ingress]# kubectl get ingress
NAME            CLASS   HOSTS              ADDRESS           PORTS   AGE
ingress-myapp   nginx   tomcat.lucky.com   192.168.244.129   80      3d14h

查看ingress,发现他成功识别到了service tomcat-svc35。

[root@master 35ingress]# kubectl describe ingress ingress-myapp
Name:             ingress-myapp
Labels:           <none>
Namespace:        default
Address:          192.168.244.129
Ingress Class:    nginx
Default backend:  <default>
Rules:Host              Path  Backends----              ----  --------tomcat.lucky.com  /   tomcat-svc35:8080 (10.244.104.47:8080,10.244.166.172:8080)
Annotations:        <none>
Events:Type    Reason  Age                From                      Message----    ------  ----               ----                      -------Normal  Sync    43m                nginx-ingress-controller  Scheduled for syncNormal  Sync    42m (x2 over 42m)  nginx-ingress-controller  Scheduled for syncNormal  Sync    37m (x2 over 38m)  nginx-ingress-controller  Scheduled for sync

这里的event信息表明,这个ingress信息是被传到了nginx-ingress-controller里,表明生效了。可以通过访问host:tomcat.lucy.com进行测试:

[root@master 35ingress]# curl http://tomcat.lucky.com<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>Apache Tomcat/8.5.41</title><link href="favicon.ico" rel="icon" type="image/x-icon" /><link href="favicon.ico" rel="shortcut icon" type="image/x-icon" /><link href="tomcat.css" rel="stylesheet" type="text/css" /></head><body>...

值得注意的是,有的时候在集群内用curl测试时可以访问,但是通过外部浏览器访问的时候,有可能浏览器会带上请求头,造成不能访问,这里用chrome的请求头进行测试,发现仍然可以。

[root@master 35ingress]# curl -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" \
>      -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" \
>      -H "Upgrade-Insecure-Requests: 1" \
>      -H "Sec-Fetch-Site: none" \
>      -H "Sec-Fetch-Mode: navigate" \
>      -H "Sec-Fetch-User: ?1" \
>      -H "Sec-Fetch-Dest: document" \
>      -H "Accept-Encoding: gzip, deflate, br" \
>      -H "Accept-Language: en-US,en;q=0.9" \
>      http://tomcat.lucky.com<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>Apache Tomcat/8.5.41</title><link href="favicon.ico" rel="icon" type="image/x-icon" /><link href="favicon.ico" rel="shortcut icon" type="image/x-icon" /><link href="tomcat.css" rel="stylesheet" type="text/css" /></head><body><div id="wrapper">...

为了防止出现以下的请求头错误造成的不能访问,可以将环境变量:use-proxy-protocol设为false。 

[error] broken header: "GET / HTTP/1.1
User-Agent: curl/7.29.0
Host: tomcat.lucky.com
Accept: */*" while reading PROXY protocol, client: 192.168.244.128, server: 0.0.0.0:80

此时继续查看ingress-controller的日志,发现记录了一条请求:

W1011 07:38:39.755918 7 client_config.go:618] Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.
I1011 07:38:39.756110 7 main.go:205] "Creating API client" host="https://10.96.0.1:443"
I1011 07:38:39.764046 7 main.go:249] "Running in Kubernetes cluster" major="1" minor="30" git="v1.30.0" state="clean" commit="7c48c2bd72b9bf5c44d21d7338cc7bea77d0ad2a" platform="linux/amd64"
I1011 07:38:39.767296 7 main.go:83] "Valid default backend" service="kube-system/default-http-backend"
I1011 07:38:39.821166 7 main.go:101] "SSL fake certificate created" file="/etc/ingress-controller/ssl/default-fake-certificate.pem"
I1011 07:38:39.852623 7 nginx.go:260] "Starting NGINX Ingress controller"
I1011 07:38:39.864591 7 event.go:298] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"kube-system", Name:"nginx-configuration", UID:"11b6a56f-d772-4ae6-8838-233241499e0a", APIVersion:"v1", ResourceVersion:"1634693", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap kube-system/nginx-configuration
I1011 07:38:40.956704 7 store.go:440] "Found valid IngressClass" ingress="default/ingress-myapp" ingressclass="nginx"
I1011 07:38:40.957552 7 event.go:298] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"ingress-myapp", UID:"1e7137d2-cfc2-4968-8486-39fe0e9329bf", APIVersion:"networking.k8s.io/v1", ResourceVersion:"1609024", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
I1011 07:38:41.054924 7 nginx.go:303] "Starting NGINX process"
I1011 07:38:41.055352 7 leaderelection.go:245] attempting to acquire leader lease kube-system/ingress-controller-leader...
I1011 07:38:41.056822 7 controller.go:190] "Configuration changes detected, backend reload required"
I1011 07:38:41.061010 7 status.go:84] "New leader elected" identity="nginx-ingress-controller-67685fb594-tl7mq"
I1011 07:38:41.141208 7 controller.go:210] "Backend successfully reloaded"
I1011 07:38:41.141470 7 event.go:298] Event(v1.ObjectReference{Kind:"Pod", Namespace:"kube-system", Name:"nginx-ingress-controller-67685fb594-8j2gv", UID:"d455926f-e6e6-411a-8096-6bde39ec3f04", APIVersion:"v1", ResourceVersion:"1635841", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I1011 07:38:41.141506 7 controller.go:221] "Initial sync, sleeping for 1 second"
I1011 07:39:19.055251 7 leaderelection.go:255] successfully acquired lease kube-system/ingress-controller-leader
I1011 07:39:19.055360 7 status.go:84] "New leader elected" identity="nginx-ingress-controller-67685fb594-8j2gv"
192.168.244.128 - - [11/Oct/2024:07:49:07 +0000] "GET / HTTP/1.1" 200 11217 "-" "curl/7.29.0" 80 0.012 [default-tomcat-svc35-8080] [] 10.244.166.170:8080 11204 0.012 200 34a616f7c18c570d50fc218a7c7896bc

 可以看到如下信息

最后一条:Ingress Controller 成功处理了一个 HTTP 请求。请求来源是 IP 地址 192.168.244.128,它发起了一个 GET / 请求,使用了 curl/7.29.0 作为 User-Agent

  • 请求结果:HTTP 状态码 200,表示请求成功。
  • 响应大小:11217 字节。
  • 处理时间:0.012 秒。
  • 后端服务:这个请求被转发到 default 命名空间中的 tomcat-svc35 服务,目标 Pod 的 IP 地址是 10.244.166.170:8080

浏览器访问tomcat 

修改电脑hosts文件,将该网址写入。

 

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

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

相关文章

自动化测试selenium篇(二)

1. 操作测试对象 1.1 普通操作 测试代码如下所示&#xff1a; private static void Test03() throws InterruptedException {//创建一个驱动WebDriver webDriver new ChromeDriver();//打开百度首页webDriver.get("https://www.baidu.com");//找到百度搜索输入框…

通过AI技术克服自动化测试难点(下)

前面的文章里我们对可以应用到测试中的AI技术做了整体介绍&#xff0c;详细介绍了OpenCV技术、OCR技术和神经网络&#xff0c;本文我们继续为大家介绍卷积神经网络、数据集以及AI技术在其他方面和测试相关的创新。 卷积神经网络整体上的原理是这样的&#xff0c;首先在底层特征…

【linux系统】进程

文章目录 进程和PCBlinux与进程的相关命令PS linux下的PCB进程标识符父子进程fork 进程状态磁盘睡眠 -- D暂停和跟踪暂停 -- T和t僵尸进程 -- Z孤儿进程 进程优先级 进程地址空间再谈fork进程地址空间分布虚拟地址和页表mm_struct 进程控制进程终止进程退出码信号 进程等待进程…

【翻译】在 Python 应用程序中使用Qt Designer的UI文件

原文地址&#xff1a;Using a Designer UI File in Your Qt for Python Application 直接上图&#xff0c;上代码 将UI文件转为Python 为了演示&#xff0c;我们使用 Qt Widgets 简单示例说明。 这个应用程序由一个源文件 easing.py、一个 UI 文件 form.UI、一个资源文件 ea…

考研笔记之操作系统(四) - 文件管理

文件管理 1. 简介1.1 前情回顾1.2 文件的属性1.3 文件内部数据的组织方式1.4 操作系统向上提供的文件功能1.5 文件应如何放在外存 2. 文件的逻辑结构2.1 无结构文件2.2 有结构文件2.2.1 顺序文件2.2.2 索引文件2.2.3 索引顺序文件2.2.4 多级索引顺序文件 3. 文件目录3.1 基本概…

1422. 分割字符串的最大得分【字符串】

文章目录 1422. 分割字符串的最大得分解题思路Go代码 1422. 分割字符串的最大得分 1422. 分割字符串的最大得分 给你一个由若干 0 和 1 组成的字符串 s &#xff0c;请你计算并返回将该字符串分割成两个 非空 子字符串&#xff08;即 左 子字符串和 右 子字符串&#xff09;所…

使用3080ti运行blip2的

使用3080ti运行blip2的案例 注意&#xff01;blip2很吃显存&#xff0c;需要大于80GB显存的卡。我最后安装的所有包的版本信息&#xff08;python 3.9 &#xff09;以供参考&#xff1a; 首先&#xff0c;我在运行blip2的demo的时候显存用了80G以上&#xff0c;所以大家卡的显存…

moectf-Web题解

1、弗拉格之地的入口 2、垫刀之路01: MoeCTF&#xff1f;启动&#xff01; 3、ez_http 4、ProveYourLove 5、弗拉格之地的挑战 6、ImageCloud前置 7、垫刀之路02: 普通的文件上传 8、垫刀之路03: 这是一个图床 9、垫刀之路05: 登陆网站 10、垫刀之路06: pop base mini …

Java值传递、序列化详解

Java 值传递详解 说到参数&#xff0c;我们先来搞懂一下这两个概念 形参&实参 值传递&引用传递 形参&实参 方法的定义可能会用到 参数&#xff08;有参的方法&#xff09;&#xff0c;参数在程序语言中分为&#xff1a; 实参&#xff08;实际参数&#xff0c;…

QT实现Opencv图像处理

案例 基于QT的人脸识别 pro文件需要加以下代码 INCLUDEPATH E:/opencv/opencv3.4-qt-intall/install/include INCLUDEPATH E:/opencv/opencv3.4-qt-intall/install/include/opencv INCLUDEPATH E:/opencv/opencv3.4-qt-intall/install/include/opencv2 LIBS E:/opencv/o…

D34【python 接口自动化学习】- python基础之输入输出与文件操作

day34 文件关闭 学习日期&#xff1a;20241011 学习目标&#xff1a;输入输出与文件操作&#xfe63;-46 常见常新&#xff1a;文件的关闭 学习笔记&#xff1a; 文件关闭的内部工作过程 close&#xff08;&#xff09;函数 with语句 常用的打开关闭文件 # 文件关闭 # 方式…

值类型和引用类型的使用

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApp1 {class Program{static void Main(string[] args){/****值类型****/bool test;//必须赋值,否则报错test true;Console.WriteLin…

微服务_3.微服务保护

文章目录 一、微服务雪崩及解决方法1.1、超时处理1.2、仓壁模式1.3、断路器1.4、限流 二、Sentinel2.1、流量控制2.1.1、普通限流2.1.2、热点参数限流 2.2、线程隔离2.3、熔断降级2.3.1、断路器状态机2.3.2、断路器熔断策略2.3.2.1、慢调用2.3.2.2、异常比例&#xff0c;异常数…

Observability:使用 OpenTelemetry 自动检测 Go 应用程序

作者&#xff1a;来自 Elastic Damien Mathieu 使用 OpenTelemetry 检测 Go 应用程序可以深入了解应用程序的性能、依赖项和错误。我们将向你展示如何使用 Docker 自动检测 Go 应用程序&#xff0c;而无需更改应用程序代码。 在快节奏的软件开发领域&#xff0c;尤其是在云原生…

【每日刷题】Day137

【每日刷题】Day137 &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;每日刷题&#x1f34d; &#x1f33c;文章目录&#x1f33c; 1. 1576. 替换所有的问号 - 力扣&#xff08;LeetCode&#xff09; 2. 495. 提莫攻击 - 力扣&#xf…

vrrp实验

配置Trunk和Access [SW3]int e0/0/1 [SW3-Ethernet0/0/1]p l a [SW3-Ethernet0/0/1]p d v 10 [SW3-Ethernet0/0/1]int e0/0/2 [SW3-Ethernet0/0/2]p l a [SW3-Ethernet0/0/2]p d v 10 [SW3-Ethernet0/0/2]int e0/0/3 [SW3-Ethernet0/0/3]p l a [SW3-Ethernet0/0/3]p d v 20 [S…

Linux——软件包管理

目录 rpm 包管理 基本介绍 rpm 包的查询指令 ​编辑 rpm 包的卸载和安装 yum rpm 包管理 基本介绍 rpm 包的查询指令 rpm 包的卸载和安装 yum

STM32F407寄存器操作(DMA+SPI)

1.前言 前面看B站中有些小伙伴吐槽F4的SPIDMA没有硬件可控的CS引脚&#xff0c;那么今天我就来攻破这个问题 我这边暂时没有SPI的从机芯片&#xff0c;并且接收的过程与发送的过程类似&#xff0c;所以这里我就以发送的过程为例了。 2.理论 手册上给出了如下的描述 我们关注…

【动手学深度学习】5.2 参数管理(个人向笔记+代码注释)

之前的课程中&#xff0c;我们只是通过深度学习框架完成训练的工作&#xff0c;而忽略了操作参数的具体细节。所以我们我们介绍的内容有&#xff1a; 访问参数&#xff0c;用于调试&#xff0c;诊断和可视化参数初始化在不同的模型组件间共享参数 下面是一个有单隐藏层的多层感…

如何把视频变成自己的原创?提升视频原创度的7个技巧

在短视频平台发布作品时&#xff0c;时常因为原创问题&#xff0c;而被限流。如何在海量视频中脱颖而出&#xff0c;让自己的作品具有独特性和原创性&#xff0c;是每位创作者都需要思考的问题。本文将详细介绍如何通过一系列前期准备和后期处理技巧&#xff0c;将视频素材转化…