我有一个 cronJob,它以某个时间间隔运行以从远程服务器下载图像。我有alpine-php:7.2-fpm
泊坞窗图像。它适用于某些 URL。但它在某些 URL 上失败了。
这是 CURL 的代码
$fp = fopen($fileNameWithPath, 'w');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_FILE => $fp,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_CONNECTTIMEOUT => 90,
CURLOPT_TIMEOUT => 180,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_VERBOSE => 1
));
$result = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);
我启用了详细,Kubernetes pods 中的日志给出了以下输出
* TCP_NODELAY set
* Connected to images.asos-media.com (23.32.5.80) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=GB; L=London; O=ASOS.com Limited; CN=*.asos-media.com
* start date: Feb 26 00:00:00 2020 GMT
* expire date: May 27 12:00:00 2021 GMT
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert Secure Site ECC CA-1
* SSL certificate verify ok.
> GET /products/wonderbra-new-ultimate-strapless-bra-a-g-cup/5980845-1-beige?$XXL$ HTTP/1.1
Host: images.asos-media.com
Accept: */*
Accept-Encoding: deflate, gzip
* old SSL session ID is stale, removing
* Operation timed out after 180000 milliseconds with 0 bytes received
* Closing connection 0
如果我在本地从 docker-image 运行此代码,它工作正常。
Kubernetes 部署文件
CronJoB
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: scheduleApp
name: imagedownlload
labels:
app: scheduleApp
spec:
schedule: "5 */4 * * *" # Specify schedule using linux cron syntax
concurrencyPolicy: Allow
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 2
jobTemplate:
spec:
parallelism: 1 # Number of Pods start together with Job
template:
metadata:
labels:
tier: cronservice
spec:
volumes:
- name: pv-restorage
persistentVolumeClaim:
claimName: pipeline-volumeclaim
containers:
- name: imagedownload
image: gcr.io/{project_id}/{image_name}:v1.0.2 # Set the image tobe used in container with full repository URL
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secret
volumeMounts:
- name: pv-restorage
mountPath: /var/www/html/restorage
restartPolicy: Never
服务文件
apiVersion: v1
kind: Service
metadata:
name: cron-loadbalancer
namespace: scheduleApp
spec:
selector:
tier: cronservice
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
- name: https
protocol: TCP
port: 443
targetPort: 443
sessionAffinity: None
type: LoadBalancer
Dockerfile
FROM php:7.2-fpm-alpine
RUN apk update && apk add \
libzip-dev \
unzip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install mysqli zip \
&& rm -rf /var/cache/apk/*
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY composer.* /var/www/html/
RUN cd /usr/local/etc/php/conf.d/ \
&& echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
WORKDIR /var/www/html
RUN composer install && composer clear-cache
COPY . /var/www/html/
ENTRYPOINT ["php","console"]
CMD ["-V"]