i使用以下命令使用此证书和私钥创建kubernetes tls机密:
kubectl创建秘密tls dpaas-secret -n dpaas-prod --key server.key --cert server.crt
这很好用,nginx入口ssl终止有效,并使用以下kubectl命令: kubectl获取秘密测试秘密-o yaml -n dpaas-prod
返回正确的输出以及tls.crt pem数据和tls.key pem数据(请参阅下面的第6步中的正确输出)
由于我们使用的是terraform,因此我尝试通过terraform kubernetes提供程序使用相同的server.key和servert.crt文件创建相同的秘密。但是这次,命令是:
kubectl获得秘密测试秘密-o yaml -n dpaas-prod
返回了crt pem和key pem的奇怪输出(请参阅下面的第5步中的输出),并且我的nginx入口上的ssl终止不起作用。
这就是我通过terraform创建kubernetes秘密的方式:
resource "kubernetes_secret" "this" {
metadata {
name = "dpaas-secret"
namespace = "dpaas-prod"
}
data = {
"tls.crt" = "${path.module}/certs/server.crt"
"tls.key" = "${path.module}/certs/server.key"
}
type = "kubernetes.io/tls"
}
*apiVersion: v1
data:
tls.crt: bXktdGVzdHMvY2VydHMvc2VydmVyLmNydA==
tls.key: bXktdGVzdHMvY2VydHMvc2VydmVyLmtleQ==
`enter code here` kind: Secret
metadata:
creationTimestamp: "2019-12-17T16:18:22Z"
name: dpaas-secret
namespace: dpaas-prod
resourceVersion: "9879"
selfLink: /api/v1/namespaces/dpaas-prod/secrets/dpaas-secret
uid: d84db7f0-20e8-11ea-aa92-1269ad9fd693
type: kubernetes.io/tls*
*apiVersion: v1
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR4RENDQXF5Z0F3SUJBZ0lRZGM0cmVoOHRQNFZPN3NkTWpzc1lTVEFOQmdrcWhraUc5dzBCQVFzRkFEQkUKTVJBd0RnWURWUVFLRXdkbGVHRnRjR3hsTVJRd0VnWURWUVFMRXd0bGVHRnRjR3hsS
UdSd2N6RWFNQmdHQTFVRQpBd3dSS2k1a2NITXVaWGhoYlhCc1pTNWpiMjB3SGhjTk1Ua3hNakUzTVRZeE5UVXpXaGNOTWpreE1qRTNN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L
3VVdVg2eGhRNwppeGtVWnB2Q3ZIVHhiY1hheUNRUFUvN0xrYWIzeC9hMUtvdWlVTHdhclQxdmE1OW1TNTF1SlkzSEJuK3RNOGZXCnNHZ0szMVluOThJVEp6T3pQa1UrdjRFQ2dZQUpRQkFCKzhocCtPbVBhbk10Yng5ZHMydzg0MWdtRlN3ZnBXcloKYWxCQ0RqbWRLS
mVSOGJxaUxDNWJpWWZiYm1YUEhRTDBCWGV0UlI0WmNGVE5JR2FRZCtCUU9iS0gzZmtZNnRyZgpEL2RLR1hUQVUycHdRNWFSRWRjSTFNV0drcmdTM0xWWHJmZnl3bHlmL2xFempMRFhDSloyTVhyalZTYWtVOHFwCk1lY3BHUUtCZ0c0ZjVobDRtL1EvaTNJdGZJbGw4W
DFRazFUSXVDK0JkL1NGM0xVVW5JUytyODA4dzVuaTNCUnEKNXgvQjFnRUhZbTNjSTROajR5ZzEvcE1CejhPMk1PeFhVbVNVZVh6dit1MG5oOFQxUE96eDJHOTNZaVlOL0cvNQpjMlBMSFMvTTlmVjhkTEVXL0hBVFM3K0hsMDFGQlVlREhrODQrVXlha2V2ZFU2djdVZ
2ErCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
kind: Secret
metadata:
creationTimestamp: "2019-12-17T16:16:56Z"
name: dpaas-secret
namespace: dpaas-prod
resourceVersion: "9727"
selfLink: /api/v1/namespaces/dpaas-prod/secrets/dpaas-secret
uid: a5739134-20e8-11ea-a977-0a0ee9b505f9
type: kubernetes.io/tls*
问题:添加带有Terraform的秘密时,为什么kubernetes秘密pem数据短(损坏?)?
我们使用terraform版本0.12.8和kubernetes 1.13
为了复制此内容,这里是文件链接:
答案 0 :(得分:2)
问题是您将证书文件的路径编码为机密,而不是文件的内容。
如果您对示例中的秘密字符串进行base64解码,就会看到这种情况:
$ echo -n bXktdGVzdHMvY2VydHMvc2VydmVyLmNydA== | base64 -d
my-tests/certs/server.crt
$ echo -n bXktdGVzdHMvY2VydHMvc2VydmVyLmtleQ== | base64 -d
my-tests/certs/server.key
所以,代替这个:
data = {
"tls.crt" = "${path.module}/certs/server.crt"
"tls.key" = "${path.module}/certs/server.key"
}
执行此操作:
data = {
"tls.crt" = file("${path.module}/certs/server.crt")
"tls.key" = file("${path.module}/certs/server.key")
}