如何在kubernetes上运行在同一端口上侦听的两个容器?
这是我的配置:如何在kubernetes上运行在同一端口上侦听的两个容器?,kubernetes,google-cloud-platform,Kubernetes,Google Cloud Platform,这是我的配置: apiVersion: extensions/v1beta1 kind: Deployment metadata: name: wordpress labels: app: wordpress spec: replicas: 1 selector: matchLabels: app: wordpress template: metadata: labels: app: wordpress
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
terminationGracePeriodSeconds: 30
containers:
- image: wordpress:latest
name: wordpress
imagePullPolicy: "Always"
env:
- name: WORDPRESS_HOST
value: localhost
- name: WORDPRESS_DB_USERNAME
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: username
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
- image: nginx:latest
name: nginx
ports:
- containerPort: 80
name: nginx
- image: gcr.io/cloudsql-docker/gce-proxy:1.09
name: cloudsql-proxy
command: ["/cloud_sql_proxy", "--dir=/cloudsql",
"-instances=abcxyz:europe-west1:wordpressdb=tcp:3306",
"-credential_file=/secrets/cloudsql/credentials.json"]
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true
- name: ssl-certs
mountPath: /etc/ssl/certs
- name: cloudsql
mountPath: /cloudsql
volumes:
- name: wordpress-persistent-storage
gcePersistentDisk:
pdName: wordpress-disk
fsType: ext4
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
- name: ssl-certs
hostPath:
path: /etc/ssl/certs
- name: cloudsql
emptyDir:
我只想公开Nginx的端口80(作为负载平衡器)。但无法启动,容器中的日志:
2017/08/09 14:39:50 [emerg] 1#1: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/09 14:39:50 [emerg] 1#1: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/09 14:39:50 [emerg] 1#1: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/09 14:39:50 [emerg] 1#1: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/09 14:39:50 [emerg] 1#1: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2017/08/09 14:39:50 [emerg] 1#1: still could not bind()
nginx: [emerg] still could not bind()
我猜这是因为Wordpress容器已经在监听端口80
我认为他们是独立的,没有任何港口冲突。我如何解决这个问题
我认为他们是独立的,没有任何港口冲突。我如何解决这个问题
在Pod中是这样,但在一个Pod中,所有容器共享相同的网络名称空间——这是它们成为Pod的部分原因。要完成您所说的“充当负载平衡器”,请单独部署nginx Pod,并将其上游指向您将为wordpress Pod创建的服务。当然,您也可以重新定位wordpress容器正在侦听的端口,但在这样做之前需要考虑以下几点
除非您的“负载平衡器”真正考虑到负载,而不仅仅是循环负载,否则创建服务的行为自然会将流量分散到与服务中的选择器匹配的所有pod中。您的意思是在单独的pod中部署nginx容器吗?还有,我将如何重新安置港口?对于第一个问题,是的;对于第二个问题,我必须查看
wordpress:latest
图像,看看它们提供了哪些配置选项,但简短的版本是改变(我认为是)其嵌入式nginx并将其listen设置为0.0.0.0:8080代码>和相应的容器端口:8080