我有一台win10机器,在其中创建了CentOS 7.5虚拟机。我有一个简单的pod和svc,我将NodeType类型设置为svc,但是我无法将本地端口30003映射到pod端口8080。
shinyinfo-jenkins-pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: shinyinfo-jenkins
labels:
app: shinyinfo-jenkins
spec:
containers:
- name: shinyinfo-jenkins
image: shinyinfo_jenkins
imagePullPolicy: Never
ports:
- containerPort: 8080
containerPort: 50000
shinyinfo-jenkins-svc.yaml:
apiVersion: v1
kind: Service
metadata:
name: shinyinfo-jenkins-svc
spec:
type: NodePort
ports:
- name: tcp
port: 8080
nodePort: 30003
selector:
app: shinyinfo-jenkins
我有两个Yaml文件:
sudo kubectl apply -f shinyinfo-jenkins-pod.yaml
sudo kubectl apply -f shinyinfo-jenkins-svc.yaml
我登录到pod:我可以做curl localhost:8080
,看到它可以访问。
jenkins@shinyinfo-jenkins:/$ curl localhost:8080
<html>
<head>
<meta http-equiv='refresh' content='1;url=/login?from=%2F'/>
<script>window.location.replace('/login?from=%2F');
</script>
</head>
<body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Administer
-->
</body>
</html>
它尝试重定向到登录页面。
然后在虚拟机中,打开firefox,在firefox地址栏中键入localhost:30003
,它会不断尝试连接服务器,但挂在那里。
日志显示没有错误:
[master@master1 config]$ sudo kubectl logs shinyinfo-jenkins
[sudo] password for master:
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Nov 01, 2018 7:45:05 AM org.eclipse.jetty.util.log.Log initialized
INFO: Logging initialized @2136ms to org.eclipse.jetty.util.log.JavaUtilLog
...
Nov 01, 2018 7:45:16 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
...
Nov 01, 2018 7:45:32 AM hudson.WebAppMain$3
INFO: Jenkins is fully up and running
该端口似乎以tcp6协议而不是tcp运行。
[master@master1 config]$ sudo netstat -anp | grep 30003
[sudo] password for master:
tcp6 2 0 :::30003 :::* LISTEN 5208/kube-proxy
tcp6 316 0 ::1:30003 ::1:48096 CLOSE_WAIT -
tcp6 80 0 ::1:30003 ::1:53132 CLOSE_WAIT -
这里的一些专家可以给我一些提示吗?
================================================ ====
我正在使用kubernetes集群配置,而不是minikube。我尝试连接Pod端口和vm端口,但Pod端口(8080
)的连接有效,但vm port(30003
)无效。最初,端口30003
没有绑定到任何进程。在vm中时,我尝试了curl localhost:30003
,它在命令CLOSE_WAIT
中创建了sudo netstats -anp | grep 30003
记录。我只是不知道为什么30003
无法映射到Pod端口8080
。如何查看服务端口?
[master@master1 config]$ sudo kubectl get po
NAME READY STATUS RESTARTS AGE
mysql 1/1 Running 0 36s
redis 1/1 Running 0 1m
shinyinfo-jenkins 1/1 Running 0 8s
[master@master1 config]$ sudo kubectl apply -f shinyinfo-jenkins-svc.yaml
service/shinyinfo-jenkins-svc created
[master@master1 config]$ curl localhost:30003
^C
[master@master1 config]$ sudo netstat -anp | grep 30003
tcp6 1 0 :::30003 :::* LISTEN 5235/kube-proxy
tcp6 80 0 ::1:30003 ::1:53126 CLOSE_WAIT -
tcp6 0 0 ::1:53126 ::1:30003 FIN_WAIT2 -
[master@master1 config]$ sudo kubectl exec -it shinyinfo-jenkins -- /bin/bash
jenkins@shinyinfo-jenkins:/$ curl localhost:8080
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Administer
-->
</body></html> jenkins@shinyinfo-jenkins:/$
jenkins@shinyinfo-jenkins:/$ exit
exit
[master@master1 config]$
================================================ =============
配置vm网络时,我创建了仅主机适配器,其地址为192.168.56.103 (enp0s8)
,并且vm的NAT连接到具有ipv4地址的Internet
10.0.2.9 (enp0s3)
,当我执行curl 192.168.56.103:30003
和curl 10.0.2.9:30003
时都可以工作。
两者都可以。为什么卷曲localhost:30003
不起作用?与我的/etc/hosts
有关的东西吗?我将/ect/hosts
放在此版本的底部。
[master@master1 ~]$ sudo kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1h
shinyinfo-jenkins-svc NodePort 10.101.23.232 <none> 8080:30003/TCP 1h
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[master@master1 ~]$ curl 10.101.23.232:8080
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Administer
-->
</body></html> [master@master1 ~]$
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[master@master1 ~]$ curl 10.0.2.9:30003
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Administer
-->
</body></html>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[master@master1 ~]$ curl 192.168.56.103:30003
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Administer
-->
</body></html>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[master@master1 ~]$ ifconfig
cali06603f21a57: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1440
inet6 fe80::ecee:eeff:feee:eeee prefixlen 64 scopeid 0x20<link>
ether ee:ee:ee:ee:ee:ee txqueuelen 0 (Ethernet)
'''
calie7aebb24de0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1440
inet6 fe80::ecee:eeff:feee:eeee prefixlen 64 scopeid 0x20<link>
ether ee:ee:ee:ee:ee:ee txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:8c:b5:7b:d9 txqueuelen 0 (Ethernet)
...
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.9 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::df00:5aa6:15fa:1bea prefixlen 64 scopeid 0x20<link>
...
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.103 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::92c6:2f30:8517:e40b prefixlen 64 scopeid 0x20<link>
...
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
...
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tunl0: flags=193<UP,RUNNING,NOARP> mtu 1440
inet 100.97.40.64 netmask 255.255.255.255
tunnel txqueuelen 1000 (IPIP Tunnel)
...
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
...
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.56.103 master1
10.0.2.9 master1