太多的挣扎,我需要分享。
需要:GET
/POST
从dev_appserver
https://ip_cluster_/apis/v1/xxx
(用于本地测试(
错误:Invalid and/or missing SSL certificate for URL
原因:k8s 集群终端节点使用自动签名证书
尝试:
- 使用带有入口的 Let's Encrypt 证书。失败,因为让我们加密需要 DNS
- 要求 AppEngine 进行不安全的连接:全球与
main.app
中的PYTHONHTTPSVERIFY: 0
连接,本地与validate_certificate=None
url_fetch
连接或verify=False
连接requests
。失败,因为 AppEngine 中不允许与自动签名证书进行不安全的 SSL 连接。公关 : https://github.com/GoogleCloudPlatform/python-compat-runtime/pull/124 - 从
https://container.googleapis.com/v1beta1/projects/<my-gcp-project>/locations/<location>/clusters/<my-cluster>
获取证书/密钥,解码base64,写入文件,将它们与requests
中的cert=('cluster_k8s.cert', 'cluster_k8s.key')
一起使用。失败,因为在 AppEngine 中禁用了本地证书支持。将它们与 curl 一起使用就可以了。明显地。 - 获取如上所述的证书/密钥,并将它们添加为谷歌云 SDK 中的自定义证书:
gcloud config set core/custom_ca_certs_file=my_cert.pem
.失败是因为生活很艰难。 - 获取上述证书/密钥,并将它们附加到谷歌云 sdk 中:
cd /usr/lib/google-cloud-sdk/platform/google_appengine/lib/cacerts/ cat my_cert >> urlfetch_cacerts.txt
失败是因为生活更加艰难。
解决方案:使用 kubectl 代理,如kubectl proxy --port=8001
k8s 服务可通过 http 从http://localhost:8001
访问
在 AppEngine 中使用如下代码切换终端节点:
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
# Production
else:
# Local development server