我想部署一個應用程式,pod 不應該進入運行狀態(它應該是不可操作的)。當確實需要使用基礎設施即代碼 (Terraform) 時,用戶可能會觸發它。我知道使用kubectl scale -- replicas=0 . 任何其他線索或資訊將不勝感激。
uj5u.com熱心網友回復:
你可以保持副本計數為零的部署或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
}
}
}
}
}
}
如果不想使用 Terraform,沒有其他方法可以使用Kubernetes的客戶端來執行此操作。
如果要使用 terraform checkout local-exec編輯本地檔案
這會呼叫運行 Terraform 的機器上的行程,而不是資源上的行程。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/331134.html
