我想部署一个应用程序,并且 pod 不应进入运行状态(它应该是不可运行的)。当确实需要使用基础架构即代码 (Terraform) 时,用户可能会触发此操作。我知道使用 kubectl scale -- replicas=0
。任何其他线索或信息将不胜感激。
最佳答案
您可以将 Deployment 或 POD 的副本数保持在 零 到您的 YAML 文件中,如果您正在使用它。
或者,如果您使用的是 Terraform
resource "kubernetes_deployment" "example" {
metadata {
name = "terraform-example"
labels = {
test = "MyExampleApp"
}
}
spec {
replicas = 0
selector {
match_labels = {
test = "MyExampleApp"
}
}
template {
metadata {
labels = {
test = "MyExampleApp"
}
}
spec {
container {
image = "nginx:1.7.8"
name = "example"
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
liveness_probe {
http_get {
path = "/nginx_status"
port = 80
http_header {
name = "X-Custom-Header"
value = "Awesome"
}
}
initial_delay_seconds = 3
period_seconds = 3
}
}
}
}
}
}
没有其他方法可以使用 client如果不想使用 Terraform,Kubernetes 可以执行此操作。
如果要使用 terraform checkout local-exec 编辑本地文件
This invokes a process on the machine running Terraform, not on the resource.
resource "aws_instance" "web" {
# ...
provisioner "local-exec" {
command = "echo ${self.private_ip} >> private_ips.txt"
}
}
在 local-exec 中使用 sed 命令或您可以更新 YAML 并应用它的任何其他命令。
https://www.terraform.io/docs/language/resources/provisioners/local-exec.html
关于kubernetes - 如何通过 gitlab CI 部署 Stale Pod(我的意思是无法运行)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69641782/