如何在Kubernetes中配置多个服务/容器? [英] How to configure multiple services/containers in Kubernetes?

查看:151
本文介绍了如何在Kubernetes中配置多个服务/容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker和Kubernetes的新手. 使用的技术:

I am new to Docker and Kubernetes. Technologies used:

  • Dotnet Core 2.2
  • Asp.NET Core WebAPI 2.2
  • 启用了Kubernetes支持的Windows(Edge)Docker
  • 代码
  • Dotnet Core 2.2
  • Asp.NET Core WebAPI 2.2
  • Docker for windows(Edge) with Kubernetes support enabled
  • Code

我将两个服务托管到两个docker容器container1和container2中.

I am having two services hosted into two docker containers container1 and container2.

下面是我的deploy.yaml

Below is my deploy.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapi-dockerkube
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: webapi-dockerkube
    spec:
      containers:
      - name: webapi-dockerkube
        image: "webapidocker:latest"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /api/values
            port: 80
        readinessProbe:
          httpGet:
            path: /api/values
            port: 80
      - name: webapi-dockerkube2
        image: "webapidocker2:latest"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /api/other/values
            port: 80
        readinessProbe:
          httpGet:
            path: /api/other/values
            port: 80

当我运行命令时:

kubectl create -f .\deploy.yaml

我的身份为CrashLoopBackOff.

但是当我仅配置一个容器时,同样运行良好. 当检查日志时,出现以下错误: Error from server (BadRequest): a container name must be specified for pod webapi-dockerkube-8658586998-9f8mk, choose one of: [webapi-dockerkube webapi-dockerkube2]

But same is running fine when i have only one container configured. When checking logs I am getting following error: Error from server (BadRequest): a container name must be specified for pod webapi-dockerkube-8658586998-9f8mk, choose one of: [webapi-dockerkube webapi-dockerkube2]

推荐答案

您正在同一容器中运行将两个端口都绑定到端口80的两个容器.在同一容器中这是不可能的. 可以将Pod视为服务器",并且不能将两个进程绑定到同一端口.

You are running two containers in the same pod which bind both to port 80. This is not possible within the same pod. Think of a pod like a 'server' and you can't have two processes bind to the same port.

您所处的解决方案:使用容器内的其他端口或使用单独的容器.在您的部署中,似乎没有像文件系统这样的共享资源,因此很容易将容器拆分为单独的Pod.

Solution in your situation: Use different ports inside the pod or use separate pods. From your deployment there seems to be no shared resources like filesystem, so it would be easy to split the containers to separate pods.

请注意,如果要使两个容器都在具有不同端口的同一个Pod中运行,则更改Pod定义是不够的.容器中的应用程序也必须绑定到其他端口.

Note that it will not suffice to change the pod definition if you want to have both containers running in the same pod with different ports. The application in the container must bind to a different port as well.

这篇关于如何在Kubernetes中配置多个服务/容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆