无法创建部署没有复制控制器在kubernetes客户端去

问题描述:

问题是我不能创建一个部署规格,而不创建复制控制器随着它。我不想使用复制控制器,因为我的应用程序总是只使用一个吊舱和我想设置重新启动策略,以防止任何终止的容器尝试重新启动。无法创建部署没有复制控制器在kubernetes客户端去

apiVersion: v1 
kind: Pod 
metadata: 
    name: two-containers 
spec: 
restartPolicy: Never 

    volumes: 
    - name: shared-data 
    emptyDir: {} 

    containers: 

    - name: nginx-container 
    image: nginx 
    volumeMounts: 
    - name: shared-data 
     mountPath: /usr/share/nginx/html 

    - name: debian-container 
    image: debian 
    volumeMounts: 
    - name: shared-data 
     mountPath: /pod-data 
    command: ["/bin/sh"] 
    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"] 

以上为目标YAML文件,我想实现与kubernetes客户去了,但是客户去目前只提供了复制控制器部署部署。

// Define Deployments spec. 
    deploySpec := &v1beta1.Deployment{ 
     TypeMeta: unversioned.TypeMeta{ 
      Kind:  "Deployment", 
      APIVersion: "extensions/v1beta1", 
    }, 
    ObjectMeta: v1.ObjectMeta{ 
     Name: "binary-search", 
    }, 
    Spec: v1beta1.DeploymentSpec{ 
     Replicas: int32p(1), 
     Template: v1.PodTemplateSpec{ 
      ObjectMeta: v1.ObjectMeta{ 
       Name: appName, 
       Labels: map[string]string{"app": appName}, 
      }, 
      Spec: v1.PodSpec{ 
       Containers: []v1.Container{ 
        v1.Container{ 
         Name: "nginx-container", 
         Image: "nginx", 
         VolumeMounts: []v1.VolumeMount{ 
          v1.VolumeMount{ 
           MountPath: "/usr/share/nginx/html", 
           Name:  "shared-data", 
          }, 
         }, 
        }, 
        v1.Container{ 
         Name: "debian-container", 
         Image: "debian", 
         VolumeMounts: []v1.VolumeMount{ 
          v1.VolumeMount{ 
           MountPath: "/pod-data", 
           Name:  "shared-data", 
          }, 
         }, 
         Command: []string{ 
          "/bin/sh", 
         }, 
         Args: []string{ 
          "-c", 
          "echo Hello from the debian container > /pod-data/index1.html", 
         }, 
        }, 
       }, 
       RestartPolicy: v1.RestartPolicyAlways, 
       DNSPolicy:  v1.DNSClusterFirst, 
       Volumes: []v1.Volume{ 
        v1.Volume{ 
         Name: "shared-data", 
         VolumeSource: v1.VolumeSource{ 
          EmptyDir: &v1.EmptyDirVolumeSource{}, 
         }, 
        }, 
       }, 
      }, 
     }, 
    }, 
    } 



// Implement deployment update-or-create semantics. 
deploy := c.Extensions().Deployments(namespace) 
    _, err := deploy.Update(deploySpec) 

有什么建议吗?提前谢谢了!

+0

副本集现代替代复制控制器...保证您使用kubernetes的当前版本 –

如果您不希望服务重新启动,那么您可以直接使用Pod。没有必要使用部署,因为这些只有意义,如果你想有自动的Pod重新启动和更新的推出。

的代码看起来在某种程度上是这样的(未测试):

podSpec := v1.PodSpec{ 
    Containers: []v1.Container{ 
     v1.Container{ 
      Name: "nginx-container", 
      Image: "nginx", 
      VolumeMounts: []v1.VolumeMount{ 
       v1.VolumeMount{ 
        MountPath: "/usr/share/nginx/html", 
        Name:  "shared-data", 
       }, 
      }, 
     }, 
     v1.Container{ 
      Name: "debian-container", 
      Image: "debian", 
      VolumeMounts: []v1.VolumeMount{ 
       v1.VolumeMount{ 
        MountPath: "/pod-data", 
        Name:  "shared-data", 
       }, 
      }, 
      Command: []string{ 
       "/bin/sh", 
      }, 
      Args: []string{ 
       "-c", 
       "echo Hello from the debian container > /pod-data/index1.html", 
      }, 
     }, 
    }, 
    RestartPolicy: v1.RestartPolicyAlways, 
    DNSPolicy:  v1.DNSClusterFirst, 
    Volumes: []v1.Volume{ 
     v1.Volume{ 
      Name: "shared-data", 
      VolumeSource: v1.VolumeSource{ 
       EmptyDir: &v1.EmptyDirVolumeSource{}, 
      }, 
     }, 
    }, 
} 

// Implement deployment update-or-create semantics. 
deploy := c.Core().PodsGetter(namespace) 
_, err := deploy.Update(podSpec)