Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
容器的Kubernetes服务选择器_Kubernetes_Service - Fatal编程技术网

容器的Kubernetes服务选择器

容器的Kubernetes服务选择器,kubernetes,service,Kubernetes,Service,我在一个吊舱中有两个集装箱,Kubernetes服务有一个到吊舱的选择器 容器1是一个UI,公开端口8080。 容器2是一个与Git同步的服务 我遇到的问题是,当“Container 2”死亡时(例如,因为Git关闭),Kubernetes服务将pod从池中移除,并且该服务没有将流量路由到pod 我如何在Kubernetes服务中将选择器设置为容器而不是pod,或者一些解决方法 --- apiVersion: v1 kind: Service metadata: name: myapp

我在一个吊舱中有两个集装箱,Kubernetes服务有一个到吊舱的选择器

容器1是一个UI,公开端口8080。 容器2是一个与Git同步的服务

我遇到的问题是,当“Container 2”死亡时(例如,因为Git关闭),Kubernetes服务将pod从池中移除,并且该服务没有将流量路由到pod

我如何在Kubernetes服务中将选择器设置为容器而不是pod,或者一些解决方法

---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: git
          image: git:1.0

        - name: ui
          image: ui:1.0
          ports:
            - containerPort: 8080

谢谢

虽然POD可以运行多个容器,但这些容器的故障由Kubernetes一起管理。你可以在这里

当一个pod运行两个容器时,理想情况下,第二个容器必须是一个辅助容器-类似于SideCar实现,它只更新或读取主容器使用的数据

kubernetes的Pod生命周期文件清楚地解释了这一点

Pod正在运行,有两个容器
容器1失败退出:

记录失败事件
如果重新启动策略为:始终
重启容器
Pod阶段保持运行
如果重新启动策略为:OnFailure
重启容器
Pod阶段保持运行
如果重新启动策略为:从不
不要重启容器
Pod阶段保持运行

如果容器1未运行,而容器2退出: 记录失败事件

如果重新启动策略为:始终
重启容器
Pod阶段保持运行。
如果重新启动策略为:OnFailure
重启容器
Pod阶段保持运行
如果重新启动策略为:从不
Pod阶段失败


虽然POD可以运行多个容器,但这些容器的故障由Kubernetes一起管理。你可以在这里

当一个pod运行两个容器时,理想情况下,第二个容器必须是一个辅助容器-类似于SideCar实现,它只更新或读取主容器使用的数据

kubernetes的Pod生命周期文件清楚地解释了这一点

Pod正在运行,有两个容器
容器1失败退出:

记录失败事件
如果重新启动策略为:始终
重启容器
Pod阶段保持运行
如果重新启动策略为:OnFailure
重启容器
Pod阶段保持运行
如果重新启动策略为:从不
不要重启容器
Pod阶段保持运行

如果容器1未运行,而容器2退出: 记录失败事件

如果重新启动策略为:始终
重启容器
Pod阶段保持运行。
如果重新启动策略为:OnFailure
重启容器
Pod阶段保持运行
如果重新启动策略为:从不
Pod阶段失败

我如何在Kubernetes服务中将选择器设置为容器而不是pod,或者一些解决方法

---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: git
          image: git:1.0

        - name: ui
          image: ui:1.0
          ports:
            - containerPort: 8080
不,你不能。 任何解决方法(如果有的话)都将是一种k8s反模式,只是因为部署不是为此而设计的。更多信息:

kubectl explain deployment.spec.template.metadata
kubectl explain deployment.spec.template.spec.containers
我如何在Kubernetes服务中将选择器设置为容器而不是pod,或者一些解决方法

---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: git
          image: git:1.0

        - name: ui
          image: ui:1.0
          ports:
            - containerPort: 8080
不,你不能。 任何解决方法(如果有的话)都将是一种k8s反模式,只是因为部署不是为此而设计的。更多信息:

kubectl explain deployment.spec.template.metadata
kubectl explain deployment.spec.template.spec.containers

为什么要将这两个容器作为同一部署的一部分运行?容器是否可以拆分为两个不同的部署?@mrbit01将它们作为一个部署运行,因为需要在同一个pod上运行两个容器。我们已经在下面解释了kubernetes建议的可能用例,为什么在同一个部署中运行这两个容器?容器是否可以拆分为两个不同的部署?@mrbit01将它们作为一个部署运行,因为需要在同一个pod上运行两个容器。下面解释了kubernetes建议的可能用例