【解决了一个小问题】因为镜像证书的问题,golang http client出现错误 `tls: failed to verify certificate: x509: certificate signed by unknown authority`
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢!
一个服务使用 Docker 打包镜像,部署到 k8s 后出现如下的错误信息:
tls: failed to verify certificate: x509: certificate signed by unknown authority
出错的位置是 golang 的 http client,并未有很特殊的配置。
最后发现是因为使用了 debian 的镜像:
FROM debian:bullseye
解决办法是加上证书更新的语句:
#FROM debian:bullseye
# 基础镜像的证书未更新,导致 https 的请求出现类似错误
# tls: failed to verify certificate: x509: certificate signed by unknown authority
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
使用最小镜像也能解决这个问题:
FROM alpine:3.20.0