kisshexuxia 2024-04-13 16:59 采纳率: 0%
浏览 18

麒麟V10下离线部署Rancher无法打开监控

背景:

最近适配国产化信创,使用银河麒麟SP3服务器版本,在用rancher部署K8S后,启用监控模块,无法启动,查看是命名空间: cattle-prometheus下的grafana-cluster-monitoring有异常,追踪下去是子pod grafana-proxy启动时候查看错误日志nginx: [emerg] host not found in upstream "localhost" in /nginx/nginx.conf:33

img

img

######正常的Nginx.conf


worker_processes      auto;
error_log             /dev/stdout warn;
pid                   /var/cache/nginx/nginx.pid;

events {
   worker_connections 1024;
}

http {
  include       /etc/nginx/mime.types;
  log_format    main '[$time_local - $status] $remote_addr - $remote_user $request ($http_referer)';

  proxy_connect_timeout       10;
  proxy_read_timeout          180;
  proxy_send_timeout          5;
  proxy_buffering             off;
  proxy_cache_path            /var/cache/nginx/cache levels=1:2 keys_zone=my_zone:100m inactive=1d max_size=10g;

  server {
    listen          8080;
    access_log      off;

    gzip            on;
    gzip_min_length 1k;
    gzip_comp_level 2;
    gzip_types      text/plain application/javascript application/x-javascript text/css application/xml text/javascript image/jpeg image/gif image/png;
    gzip_vary       on;
    gzip_disable    "MSIE [1-6]\.";

    proxy_set_header Host $host;

    location /api/dashboards {
      proxy_pass     http://localhost:3000;
    }

    location /api/search {
      proxy_pass     http://localhost:3000;

      sub_filter_types application/json;
      sub_filter_once off;
      sub_filter '"url":"/d' '"url":"d';
    }

    location / {
      proxy_cache         my_zone;
      proxy_cache_valid   200 302 1d;
      proxy_cache_valid   301 30d;
      proxy_cache_valid   any 5m;
      proxy_cache_bypass  $http_cache_control;
      add_header          X-Proxy-Cache $upstream_cache_status;
      add_header          Cache-Control "public";
      
      proxy_pass     http://localhost:3000/;

      sub_filter_types text/html;
      sub_filter_once off;
      sub_filter '"appSubUrl":""' '"appSubUrl":"."';
      sub_filter '"url":"/' '"url":"./';
      sub_filter ':"/avatar/' ':"avatar/';

      if ($request_filename ~ .*\.(?:js|css|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$) {
        expires             90d;
      }
    }
  }
}[rancher@rancher1 ~]$ 
操作环境:

银河麒麟SP3服务器版本、软件版本:rancher2.4.5 Kubernetes 版本: v1.18.3 docker EC18.0.9和20都测了

尝试过的解决方法

和Cenos7.9部署的环境进行了比较,发现麒麟下执行kubectl命令行,cat /etc/hosts没权限,vi打开文件是空的,看错误日志应该是这个空的引起Nginx 配置localhost无法解析。

# Run kubectl commands inside here
# e.g. kubectl get all
> cat /etc/hosts
cat: /etc/hosts: Permission denied
> 

在Centos7.9下执行正常

# Kubernetes-managed hosts file.
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.42.1.113     grafana-cluster-monitoring-855c6cdd4-n2hhf

2个系统中的hosts的权限分别是
-rw-r--r--. 1 root root 206 Oct 31 13:13 hosts(Centos)
-rw-r----- 1 root root 206 Apr 12 13:38 hosts(麒麟)

kubectl -n cattle-prometheus patch  deployments grafana-cluster-monitoring --patch '{
    "spec": {
        "template": {
            "spec": {
                "hostAliases": [
                    {
                        "hostnames":
                        [
                            "localhost"
                        ],
                            "ip": "127.0.0.1"
                    }
                ]
            }
        }
    }
}'

我想要达到的结果

grafana-cluster-monitoring能和Centos7.9环境一样新增pod中的hosts权限正常

  • 写回答

5条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-04-13 16:59
    关注

    引自免费微信小程序:皆我百晓生

    针对你在麒麟V10环境下遇到的问题,Rancher 的 Grafana 监控模块无法启动,并且报错 nginx: [emerg] host not found in upstream "localhost",这通常是因为 Nginx 无法正确地将流量转发到本地服务,可能是由于 /etc/hosts 文件没有正确的配置。

    解决这个问题可以尝试通过为 Grafana 的 Pod 添加 Host Aliases,这样它就可以访问 localhost 而不需要依赖于 /etc/hosts 文件。下面是具体的步骤:

    1. 使用下面的 YAML 来更新 grafana-cluster-monitoring Deployment,添加一个 Host Alias 到 Pod 的配置中,使 Pod 可以通过 localhost 访问 127.0.0.1:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: grafana-cluster-monitoring
      namespace: cattle-prometheus
    spec:
      template:
        spec:
          hostAliases:
          - ip: "127.0.0.1"
            hostnames:
            - "localhost"
          containers:
          # ... (这里保留原有的 containers 配置)
    
    1. 将上面的 YAML 内容保存为一个文件,例如 update_grafana.yaml,然后应用这些更改:
    kubectl apply -f update_grafana.yaml -n cattle-prometheus
    
    1. 如果上述方法无效,可能还需要更新 Grafana 的配置本身,确保它使用的代理指向正确的地址。可以在 Grafana 的数据卷中添加一个配置文件,覆盖默认配置。创建一个名为 grafana.ini 的文件,内容如下:
    [server]
    http_port = :80
    root_url = http://localhost:3000/
    
    [proxy]
    upstream_url = http://localhost:8080/
    
    1. 然后,将此配置文件添加到 Grafana 的 Deployment 中:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: grafana-cluster-monitoring
      namespace: cattle-prometheus
    spec:
      template:
        spec:
          volumes:
          - name: grafana-config
            configMap:
              name: grafana-configmap
          containers:
          - name: grafana-proxy
            volumeMounts:
            - mountPath: /etc/grafana/conf
              name: grafana-config
          # ... (这里保留原有的 containers 配置)
    
    1. 创建一个 ConfigMap 来存储 grafana.ini 文件:
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: grafana-configmap
    data:
      grafana.ini: |-
        [server]
        http_port = :80
        root_url = http://localhost:3000/
    
        [proxy]
        upstream_url = http://localhost:8080/
    
    1. 应用这个 ConfigMap:
    kubectl apply -f grafana-configmap.yaml -n cattle-prometheus
    
    1. 最后,更新 Grafana 的 Deployment 以应用新的 ConfigMap:
    kubectl set env deployment grafana-cluster-monitoring grafana_config_map=grafana-configmap -n cattle-prometheus
    

    完成上述操作后,Grafana 应该能够正确地使用代理并将流量转发给内部服务,从而解决监控模块无法启动的问题。如果还有任何问题,请检查 Grafana 和相关组件的日志,以便进一步排查。

    评论 编辑记录

报告相同问题?

问题事件

  • 修改了问题 4月13日
  • 创建了问题 4月13日

悬赏问题

  • ¥15 ssh登录页面的问题
  • ¥60 渗透一个指定银行app,拿到客户信息,需要什么级别
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥15 stm32 串口通讯过程中的问题
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问