【发布时间】:2020-02-13 00:44:23
【问题描述】:
下面是包含多个容器的 pod 的 configMap 文件。 端口号 80 暴露给外部世界,然后它将重定向到在 pod 中运行的另一个容器的端口 5000。
apiVersion: v1
kind: ConfigMap
metadata:
name: mc3-nginx-conf
data:
nginx.conf: |-
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream webapp {
server 127.0.0.1:5000;
}
server {
listen 80;
location / {
proxy_pass http://webapp;
proxy_redirect off;
}
}
}
$kubectl apply -f confimap.yaml
pod 配置:
apiVersion: v1
kind: Pod
metadata:
name: mc3
labels:
app: mc3
spec:
containers:
- name: webapp
image: training/webapp
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: nginx-proxy-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-proxy-config
configMap:
name: mc3-nginx-conf
步骤 3. 使用 NodePort 服务公开 Pod:
$ kubectl expose pod mc3 --type=NodePort --port=80
service "mc3" exposed
步骤 4. 识别节点上转发到 Pod 的端口:
$ kubectl describe service mc3
Name: mc3
Namespace: default
Labels: app=mc3
Annotations: <none>
Selector: app=mc3
Type: NodePort
IP: 100.68.152.108
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 32636/TCP
Endpoints: 100.96.2.3:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
但我无法执行 curl
$ curl 100.96.2.3:80
$ curl http://100.96.2.3:80
$ curl http://100.96.2.3:32636
所以,我想知道为什么这个重定向不起作用。
来源:https://www.mirantis.co.jp/blog/multi-container-pods-and-container-communication-in-kubernetes/
它写在我们可以使用url访问的页面上
现在,这里的 myhost 是什么? 而且,我知道暴露的端口是 32636
但是,我无法从浏览器或 curl /wget 命令访问。
【问题讨论】:
-
您在什么平台上进行部署,您的节点端口是否暴露在互联网上?您是否使用堡垒从提供程序内部卷曲?
-
我在 google cloud shell 上执行。 Nodeport 不暴露在互联网上,而是暴露在 pod 之外的本地环境中。您可以参考还显示图表的链接。单pod多容器架构,容器端口转发的地方。所以从谷歌云外壳本身我正在执行 curl 命令和 wget 命令。
-
好的,所以第三种形式是好的...现在你有没有ipaliasing?
-
我实际上尝试过你配置映射、pod 和服务,它们对我来说工作正常,你可能使用了错误的 IP 地址,你应该卷曲到的地址是你的集群之一的 IP 地址节点
-
你应该添加到你的问题,outout:
Kubectl get all,也许你的 pod 还没有运行。
标签: kubernetes