kubernetes集群部署成功后,在浏览器输入Linux主机IP地址+port端口号访问,无法访问的问题解决

1、这里以k8s单机集群部署为例,所有服务启动完毕

systemctl start etcd
systemctl start docker
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
systemctl start kubelet.service
systemctl start kube-proxy.service

2、在Xshell界面输入

[root@localhost ~]# curl 主机IP地址:port端口号,可以顺利输出
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Apache Tomcat/8.0.35</title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        <div id="wrapper">
            <div id="navigation" class="curved container">
                <span id="nav-home"><a href="http://tomcat.apache.org/">Home</a></span>
                <span id="nav-hosts"><a href="/docs/">Documentation</a></span>
                <span id="nav-config"><a href="/docs/config/">Configuration</a></span>
                <span id="nav-examples"><a href="/examples/">Examples</a></span>
                <span id="nav-wiki"><a href="http://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
                <span id="nav-lists"><a href="http://tomcat.apache.org/lists.html">Mailing Lists</a></span>
                <span id="nav-help"><a href="http://tomcat.apache.org/findhelp.html">Find Help</a></span>
                <br class="separator" />
            </div>
            <div id="asf-box">
                <h1>Apache Tomcat/8.0.35</h1>
            </div>
            <div id="upper" class="curved container">
                <div id="congrats" class="curved container">
                    <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
                </div>
                <div id="notice">
                    <img src="tomcat.png" alt="[tomcat logo]" />
                    <div id="tasks">
                        <h3>Recommended Reading:</h3>
                        <h4><a href="/docs/security-howto.html">Security Considerations HOW-TO</a></h4>
                        <h4><a href="/docs/manager-howto.html">Manager Application HOW-TO</a></h4>
                        <h4><a href="/docs/cluster-howto.html">Clustering/Session Replication HOW-TO</a></h4>
                    </div>
                </div>
                <div id="actions">
                    <div class="button">
                        <a class="container shadow" href="/manager/status"><span>Server Status</span></a>
                    </div>
                    <div class="button">
                        <a class="container shadow" href="/manager/html"><span>Manager App</span></a>
                    </div>
                    <div class="button">
                        <a class="container shadow" href="/host-manager/html"><span>Host Manager</span></a>
                    </div>
 .............
 .............
 .............
 省略
  表示集群部署成功,可以顺利访问

3、在浏览器中输入主机IP地址+port端口号却访问不了,原因在于Linux主机自带防火墙,拦截了访问所导致,因此只要修改防火墙即可,这里是停掉防火墙

首先查看防火墙状态:systemctl status iptables.service
暂时停掉防火墙:systemctl stop iptables.service

4、关于防火墙状态查看、操作的命令

查看防火墙是否开机自启:systemctl list-unit-files | grep iptables.service
停止防火墙:systemctl stop iptables.service
启动防火墙:systemctl start iptables.service
重启一个服务:systemctl restart iptables.service
显示防火墙状态:systemctl status iptables.service
开机时启动防火墙:systemctl enable iptables.service
开机时禁止防火墙自启:systemctl disable  iptables.service
查看防火墙是否开机自启:systemctl is-enabled  iptables.service;echo $?
查看已启动的服务列表:systemctl list-unit-files|grep enabled

5、CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。

firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
如果使用firewall-cmd --state输出-bash: firewall-cmd: 未找到命令,可以使用yum list firewall*
查找可安装的软件和依赖包,再使用yum install firewall(可能名字不是这个)来安装,firewall-cmd
命令就可以使用了

6、从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig。

systemctl list-unit-files|grep firewalld.service #查看防火墙状态
或者
systemctl status firewalld.service

Centos 7 firewall 命令:

查看已经开放的端口:

firewall-cmd --list-ports
开启端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:

–zone #作用域

–add-port=80/tcp #添加端口,格式为:端口/通讯协议

–permanent #永久生效,没有此参数重启后失效

重启防火墙

firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

猜你喜欢

转载自blog.csdn.net/cdbdqn001/article/details/85612322