具有多个负载平衡器和 pods 的单个 YAML 文件
Single YAML file with multiple load balancers and pods
我有一个 yaml 文件,我试图在其中部署 2 个负载均衡器,每个都有一个 pod 和容器。
但是,当我 运行 以下 infrastructure.yml 文件时,它会启动 2 个负载均衡器和 1 个 pod/容器 (job-base
)。它忽略了启动 api-base
pod/容器。从文件中注释掉 job-base
作业/容器,api-base
pod 正常启动。
我错过了什么?我如何获得这个单一文件来部署所有 pods 和服务?
kind: ConfigMap
apiVersion: v1
metadata:
name: api-base
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-base
spec:
replicas: 1
selector:
matchLabels:
app: api-base
template:
metadata:
labels:
app: api-base
spec:
containers:
- name: api-base
image: path/to/apiImage
ports:
- containerPort: 44360
protocol: TCP
resources:
requests:
memory: "0.4Gi"
cpu: "0.2"
limits:
memory: "0.4Gi"
cpu: "0.2"
---
apiVersion: v1
kind: Service
metadata:
name: api-base
labels:
app: api-base
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
spec:
selector:
app: api-base
ports:
- port: 80
targetPort: 44360
protocol: TCP
type: LoadBalancer
---
kind: ConfigMap
apiVersion: v1
metadata:
name: job-base
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: job-base
spec:
replicas: 1
selector:
matchLabels:
app: job-base
template:
metadata:
labels:
app: job-base
spec:
containers:
- name: job-base
image: path/to/jobImage
ports:
- containerPort: 44360
protocol: TCP
resources:
requests:
memory: "0.4Gi"
cpu: "0.2"
limits:
memory: "0.4Gi"
cpu: "0.2"
---
apiVersion: v1
kind: Service
metadata:
name: job-base
labels:
app: job-base
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
spec:
selector:
app: job-base
ports:
- port: 80
targetPort: 44360
protocol: TCP
type: LoadBalancer
更新:
如果无法在单个 yml 中完成此操作,我还会考虑 运行使用相同的负载均衡器将 api
和 job
容器连接到同一 pod 中。只要我可以在不同的端口上公开 pod 中的每个容器。
命名空间没有分配足够的资源。当尝试配置新容器时,它会因 CPU 或内存限制而失败并终止。
我通过运行以下命令发现了这个问题
kubectl get deployment api-base -o yaml
此输出 message
属性 表示由于资源问题导致最新部署失败。
增加命名空间 ResourceQuota 解决了问题:https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/
我有一个 yaml 文件,我试图在其中部署 2 个负载均衡器,每个都有一个 pod 和容器。
但是,当我 运行 以下 infrastructure.yml 文件时,它会启动 2 个负载均衡器和 1 个 pod/容器 (job-base
)。它忽略了启动 api-base
pod/容器。从文件中注释掉 job-base
作业/容器,api-base
pod 正常启动。
我错过了什么?我如何获得这个单一文件来部署所有 pods 和服务?
kind: ConfigMap
apiVersion: v1
metadata:
name: api-base
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-base
spec:
replicas: 1
selector:
matchLabels:
app: api-base
template:
metadata:
labels:
app: api-base
spec:
containers:
- name: api-base
image: path/to/apiImage
ports:
- containerPort: 44360
protocol: TCP
resources:
requests:
memory: "0.4Gi"
cpu: "0.2"
limits:
memory: "0.4Gi"
cpu: "0.2"
---
apiVersion: v1
kind: Service
metadata:
name: api-base
labels:
app: api-base
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
spec:
selector:
app: api-base
ports:
- port: 80
targetPort: 44360
protocol: TCP
type: LoadBalancer
---
kind: ConfigMap
apiVersion: v1
metadata:
name: job-base
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: job-base
spec:
replicas: 1
selector:
matchLabels:
app: job-base
template:
metadata:
labels:
app: job-base
spec:
containers:
- name: job-base
image: path/to/jobImage
ports:
- containerPort: 44360
protocol: TCP
resources:
requests:
memory: "0.4Gi"
cpu: "0.2"
limits:
memory: "0.4Gi"
cpu: "0.2"
---
apiVersion: v1
kind: Service
metadata:
name: job-base
labels:
app: job-base
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
spec:
selector:
app: job-base
ports:
- port: 80
targetPort: 44360
protocol: TCP
type: LoadBalancer
更新:
如果无法在单个 yml 中完成此操作,我还会考虑 运行使用相同的负载均衡器将 api
和 job
容器连接到同一 pod 中。只要我可以在不同的端口上公开 pod 中的每个容器。
命名空间没有分配足够的资源。当尝试配置新容器时,它会因 CPU 或内存限制而失败并终止。
我通过运行以下命令发现了这个问题
kubectl get deployment api-base -o yaml
此输出 message
属性 表示由于资源问题导致最新部署失败。
增加命名空间 ResourceQuota 解决了问题:https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/quota-memory-cpu-namespace/