gpt4 book ai didi

kubernetes - 从 terraform 运行 kubernetes build

转载 作者:行者123 更新时间:2023-12-04 12:50:36 24 4
gpt4 key购买 nike

我正在尝试进行一个简单的测试,以便在 terraform 的 kubernetes 上构建一个简单的 nginx。
这是第一次使用 terraform。

这是基本的 terraform 文件:

provider "kubernetes" {
host = "https://xxx.xxx.xxx.xxx:8443"

client_certificate = "${file("~/.kube/master.server.crt")}"
client_key = "${file("~/.kube/master.server.key")}"
cluster_ca_certificate = "${file("~/.kube/ca.crt")}"

username = "xxxxxx"
password = "xxxxxx"

}

resource "kubernetes_service" "nginx" {
metadata {
name = "nginx-example"
}
spec {
selector {
App = "${kubernetes_pod.nginx.metadata.0.labels.App}"
}
port {
port = 80
target_port = 80
}

type = "LoadBalancer"
}
}

resource "kubernetes_pod" "nginx" {
metadata {
name = "nginx-example"
labels {
App = "nginx"
}
}

spec {
container {
image = "nginx:1.7.8"
name = "example"

port {
container_port = 80
}
}
}
}

运行 terraform apply 后,我收到以下错误。

Error: Error applying plan:

1 error(s) occurred:

  • kubernetes_pod.nginx: 1 error(s) occurred:

  • kubernetes_pod.nginx: the server has asked for the client to provide credentials (post pods)

Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file has been partially updated with any resources that successfully completed. Please address the error above and apply again to incrementally change your infrastructure.



我对 kubernetes 拥有管理员权限,一切正常。
但出于某种原因,我收到了那个错误。

我做错了什么?

谢谢

关于@matthew-l-daniel 问题

当我只使用用户名/密码时,我收到此错误:

Error: Error applying plan:

1 error(s) occurred:

Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file has been partially updated with any resources that successfully completed. Please address the error above and apply again to incrementally change your infrastructure.



我尝试使用服务器名称或服务器 ip,但每次都遇到相同的错误。

使用证书时,我从原始帖子中收到了关于“凭据”的错误

我忘了提到这是一个 openshift 安装。我不相信它最终会产生任何影响,但我想我应该提到它。

最佳答案

解决方案相当简单,我在 terraform 上使用了 openshift 的主 crt 和 key 。
然后我使用来自 openshift 的 admin crt 和 key 对其进行了测试,并且成功了。

关于kubernetes - 从 terraform 运行 kubernetes build,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53454588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com