从Kubernetes Nginx入口获得响应的问题

如何解决从Kubernetes Nginx入口获得响应的问题

在通过负载均衡器提供的外部IP访问群集时遇到问题。

我已经使用centos 8在kubeadm本地设置了k8s。我的控制平面节点使用keepalived和haproxy来实现高可用性。我也在利用metallb和calico cni。

最终目标是在每个节点上设置多个Elasticsearch Pod。

keepalived.conf

! /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
        router_id LVS_DEVEL
}
vrrp_script check_apiserver {
        script "/etc/keepalived/check_apiserver.sh"
        interval 3
        weight -2
        fall 10
        rise 2
}

vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 151
        priority 255
        mcast_src_ip 172.16.93.11
        authentication {
                auth_type PASS
                auth_pass test1234
        }
        unicast_peer {
                172.16.93.12
                172.16.93.13
        }
        virtual_ipaddress {
                172.16.93.14/24
        }
        track_script {
                check_apiserver
        }
}

haproxy.cfg

global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    #chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    #user        haproxy
    #group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

    # utilize system-wide crypto-policies
    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#-------------------------------------------------------------------
# apiserver frontend which proxys to the masters
#-------------------------------------------------------------------
frontend http_stats
        bind *:8080
        mode tcp
        stats uri /haproxy?stats

frontend apiserver
        bind *:6443
        mode tcp
        option tcplog
        timeout client 10800s
        default_backend controlPlanes
#-------------------------------------------------------------------
# round robin balancing for apiserver
#-------------------------------------------------------------------
backend controlPlanes
        option httpchk GET /healthz
        option ssl-hello-chk
        mode tcp
        balance leastconn
        timeout server 10800s
        balance roundrobin
                server master-node-1 172.16.93.11:6444 check
                server master-node-2 172.16.93.12:6444 check
                server master-node-3 172.16.93.13:6444 check

所有主节点和工作节点都通过端口6443上的keepalived.conf(172.16.93.14)中提供的虚拟IP进行了连接。

出于测试目的,我有一个部署,该部署创建5个基本nginx pod的副本。

red-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
    name: red-test
    labels:
            deploymentColor: red-deployment
spec:
    replicas: 5
    selector:
            matchLabels:
                    podColor: red
    template:
            metadata:
                    labels:
                            podColor: red
            spec:
                    containers:
                            - name: nginx
                              image: nginx
                              ports:
                                      - containerPort: 80

使用以下命令在端口80上公开部署:

kubectl expose deploy red-test --port 80

nginx入口控制器的仓库:https://github.com/kubernetes/ingress-nginx

使用'--rbac.create = true'标签通过头盔安装了nginx-ingress控制器。

service / ingress-nginx-controller.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    meta.helm.sh/release-name: my-release
    meta.helm.sh/release-namespace: default
  creationTimestamp: "2020-10-30T18:24:23Z"
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: my-release
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/version: 0.40.2
    helm.sh/chart: ingress-nginx-3.7.1
  name: my-release-ingress-nginx-controller
  namespace: default
  resourceVersion: "3456923"
  selfLink: /api/v1/namespaces/default/services/my-release-ingress-nginx-controller
  uid: 6f223a76-01e2-4bb2-b4d2-dd5f8b03c8b5
spec:
  clusterIP: 10.109.91.181
  externalTrafficPolicy: Cluster
  ports:
  - name: http
    nodePort: 32275
    port: 80
    protocol: TCP
    targetPort: http
  - name: https
    nodePort: 32528
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: my-release
    app.kubernetes.io/name: ingress-nginx
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 172.16.93.50

nginx-ingress版本

NGINX Ingress controller
  Release:       v0.40.2
  Build:         fc4ccc5eb0e41be2436a978b01477fc354f31643
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.19.3

my-ingress-def.yaml

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: red-test-ing
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: red.test
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: red-test
            port:
              number: 80

metallb-configmap.yaml

---
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 172.16.93.50-172.16.93.100

kubectl获取

--svc--
service/my-release-ingress-nginx-controller             LoadBalancer   10.109.91.181    172.16.93.50   80:32275/TCP,443:32528/TCP
service/my-release-ingress-nginx-controller-admission   ClusterIP      10.106.163.96    <none>         443/TCP
service/red-test                                        ClusterIP      10.108.176.214   <none>         80/TCP
--ing--
red-test-ing   <none>   red.test   172.16.93.50   80

red.test已添加到我的/ etc / hosts文件中。我已经尝试过“卷曲”主机名,端口,节点端口,IP地址等的每个组合。我要么超时要么无法路由。

curl http://172.16.93.50:32275/ -v -H 'Host: red.test' - no route to host
curl http://red.test/ - timeout
curl http://172.16.93.50/ - timeout
etc,etc...

我已经在所有节点上运行了iptables -A FORWARD -j ACCEPT和iptables -P FORWARD ACCEPT。我可以通过普通的nodeport服务访问pod。

我一般对k8和devop还是陌生的。让我知道是否需要更多信息。非常感谢。



版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-