首页 > 解决方案 > HTTP/1.1 503 后端获取失败:Guru Meditation:XID:1066598

问题描述

我为在 kubernetes 集群中运行的 varnish 缓存服务器创建了 helm 图表,同时使用“外部 IP”进行测试产生了它的抛出错误,分享如下

共享 varnish.vcl(在我的例子中是 default.vcl 的别名),values.yaml 下面。关于如何解决的任何建议,因为我已将后端/Web 服务器硬编码为 .host="www.varnish-cache.org",端口为:"80"。我的要求是在我的情况下执行 curl -IL 负载平衡器入口 IP),我应该得到与上述不同的缓存值的响应(直接来自后端服务器)..

任何解决方案/方法如何解决这个问题。请根据我上面的 varnish(default.vcl) 和 values.yaml 文件给出任何响应/建议。请将此视为高优先级。

清漆.vcl:

 VCL version 5.0 is not supported so it should be 4.0 or 4.1 even though actually used Varnish version is 6
vcl 4.1;

import std;
# The minimal Varnish version is 5.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'



{{  .Values.varnishconfigData | indent 2 }}

sub vcl_recv {

  if(req.url == "/healthcheck") {
    return(synth(200,"OK"));
  }
}

值.yaml:

# Default values for varnish.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
  repository: varnish
  tag: 6.3
  pullPolicy: IfNotPresent

nameOverride: ""
fullnameOverride: ""

service:
 # type: ClusterIP
  type: LoadBalancer
  port: 80

varnishconfigData: |- 
       backend default {
          .host = "35.170.216.115";
          .port = "80";
          .first_byte_timeout = 60s;
          .connect_timeout = 300s ;
          .probe = {
                 .url = "/";
                 .timeout = 1s;
                 .interval = 5s;
                 .window = 5;
                 .threshold = 3;
}
         sub vcl_backend_response {
           set beresp.ttl = 5m;
         }

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  path: /
  hosts:
    - chart-example.local
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local


resources:
  limits:
    memory: 128Mi
  requests:
    memory: 64Mi




#resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  # limits:
  #  cpu: 100m
  #  memory: 128Mi
  # requests:
  #  cpu: 100m
  #  memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

标签: kubernetes-helmvarnish

解决方案


.host = "www.google.com";

使用 IP 地址而不是主机名

分享运行命令时产生的日志 varnishlog -g request -q "ReqHeader:Host eq 'a2dc15095678711eaae260ae72bc140c-214951329.ap-southeast-1.elb.amazonaws.com'" -q "ReqUrl eq '/'" 请看下..

*   << Request  >> 1512355   
-   Begin          req 1512354 rxreq
-   Timestamp      Start: 1584707667.287292 0.000000 0.000000
-   Timestamp      Req: 1584707667.287292 0.000000 0.000000
-   VCL_use        boot
-   ReqStart       100.112.64.0 51532 a0
-   ReqMethod      GET
-   ReqURL         /
-   ReqProtocol    HTTP/1.1
-   ReqHeader      Host: 52.220.214.66
-   ReqHeader      User-Agent: Mozilla/5.0 zgrab/0.x
-   ReqHeader      Accept: */*
-   ReqHeader      Accept-Encoding: gzip
-   ReqHeader      X-Forwarded-For: 100.112.64.0
-   VCL_call       RECV
-   ReqUnset       Host: 52.220.214.66
-   ReqHeader      host: 52.220.214.66
-   VCL_return     hash
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       MISS
-   VCL_return     fetch
-   Link           bereq 1512356 fetch
-   Timestamp      Fetch: 1584707667.287521 0.000228 0.000228
-   RespProtocol   HTTP/1.1
-   RespStatus     503
-   RespReason     Backend fetch failed
-   RespHeader     Date: Fri, 20 Mar 2020 12:34:27 GMT
-   RespHeader     Server: Varnish
-   RespHeader     Content-Type: text/html; charset=utf-8
-   RespHeader     Retry-After: 5
-   RespHeader     X-Varnish: 1512355
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish (Varnish/6.3)
-   VCL_call       DELIVER
-   RespHeader     X-Cache: uncached
-   VCL_return     deliver
-   Timestamp      Process: 1584707667.287542 0.000250 0.000021
-   Filters        
-   RespHeader     Content-Length: 284
-   RespHeader     Connection: keep-alive
-   Timestamp      Resp: 1584707667.287591 0.000299 0.000048
-   ReqAcct        110 0 110 271 284 555
-   End            
**  << BeReq    >> 1512356   
--  Begin          bereq 1512355 fetch
--  VCL_use        boot
--  Timestamp      Start: 1584707667.287401 0.000000 0.000000
--  BereqMethod    GET
--  BereqURL       /
--  BereqProtocol  HTTP/1.1
--  BereqHeader    User-Agent: Mozilla/5.0 zgrab/0.x
--  BereqHeader    Accept: */*
--  BereqHeader    Accept-Encoding: gzip
--  BereqHeader    X-Forwarded-For: 100.112.64.0
--  BereqHeader    host: 52.220.214.66
--  BereqHeader    X-Varnish: 1512356
--  VCL_call       BACKEND_FETCH
--  VCL_return     fetch
--  FetchError     backend default: unhealthy
--  Timestamp      Beresp: 1584707667.287429 0.000028 0.000028
--  Timestamp      Error: 1584707667.287432 0.000031 0.000002
--  BerespProtocol HTTP/1.1
--  BerespStatus   503
--  BerespReason   Service Unavailable
--  BerespReason   Backend fetch failed
--  BerespHeader   Date: Fri, 20 Mar 2020 12:34:27 GMT
--  BerespHeader   Server: Varnish
--  VCL_call       BACKEND_ERROR
--  BerespHeader   Content-Type: text/html; charset=utf-8
--  BerespHeader   Retry-After: 5
--  VCL_return     deliver
--  Storage        malloc Transient
--  Length         284
--  BereqAcct      0 0 0 0 0 0
--  End 

推荐阅读