The Pod "XX" is invalid: spec.containers: Forbidden: pod updates may not add or remove containers

创建一个pod脚本

busybox-pod.yaml 
```yaml
apiVersion: v1
kind: Pod
metadata:
    name: busybox
    namespace: dev
spec:
    containers:
        - name: busybox
          image: busybox
          command:
            - sleep
            - "3600"
```
我们来应用这个模板
```shell
# kubectl apply -f busybox-pod.yaml 
pod "busybox" configured
```
现在我们来修改这个模板,例如改一下休眠时间

busybox-pod.yaml 
```yaml
apiVersion: v1
kind: Pod
metadata:
    name: busybox
    namespace: dev
spec:
    containers:
        - name: busybox
          image: busybox
          command:
            - sleep
            - "3700"
```
再次应用这个模板
```shell
# kubectl apply -f busybox-pod.yaml 
The Pod "busybox" is invalid: spec: Forbidden: pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds`
```
如果修改其他配置,可能收到如下报错:
```
The Pod "busybox" is invalid: spec.containers: Forbidden: pod updates may not add or remove containers
```
这时,我们需要先将容器删除再重现创建
```shell
# kubectl delete pod busybox -n dev
pod "busybox" deleted
```
结论:pod无法更新

原文地址:http://www.nanstar.top/e?id=wiki_1577261390534

The Pod "nginx-pod" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)   core.PodSpec{    Volumes: []core.Volume{    {    Name: "nginx-config",    VolumeSource: core.VolumeSource{    ... // 17 identical fields    FC: nil,    AzureFile: nil,    ConfigMap: &core.ConfigMapVolumeSource{ -  LocalObjectReference: core.LocalObjectReference{Name: "nginx-config"}, +  LocalObjectReference: core.LocalObjectReference{Name: "nginx-configmap"}, -  Items: nil, +  Items: []core.KeyToPath{{Key: "nginx.conf", Path: "nginx.conf"}},    DefaultMode: &420,    Optional: nil,    },    VsphereVolume: nil,    AzureDisk: nil,    ... // 7 identical fields    },    },    {Name: "default-token-276dd", VolumeSource: core.VolumeSource{Secret: &core.SecretVolumeSource{SecretName: "default-token-276dd", DefaultMode: &420}}},    },    InitContainers: nil,    Containers: []core.Container{    {    ... // 7 identical fields    Env: nil,    Resources: core.ResourceRequirements{},    VolumeMounts: []core.VolumeMount{    {    Name: "nginx-config", -  ReadOnly: false, +  ReadOnly: true,    MountPath: "/etc/nginx/nginx.conf",    SubPath: "nginx.conf",    ... // 2 identical fields    },    {Name: "default-token-276dd", ReadOnly: true, MountPath: "/var/run/secrets/kubernetes.io/serviceaccount"},    },    VolumeDevices: nil,    LivenessProbe: nil,    ... // 10 identical fields    },    },    EphemeralContainers: nil,    RestartPolicy: "Always",    ... // 25 identical fields   }
05-25
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值