Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

15.3.4. 将服务公开给创建路由

您必须使用 oc expose 命令将服务公开为路由

公开服务:

  1. 登录 OpenShift Container Platform。
  2. 登录您想公开的服务所在的项目。

    $ oc project project1
  3. 运行以下命令以公开路由:

    $ oc expose service <service_name>

    例如:

    $ oc expose service mysql-55-rhel7
    route "mysql-55-rhel7" exposed
  4. 在 master 上,使用 cURL 等工具来确保您可以使用服务的集群 IP 地址访问该服务:

    $ curl <pod_ip>:<port>

    例如:

    $ curl 172.30.131.89:3306

    此部分中的示例使用 MySQL 服务,这需要客户端应用程序。如果您得到一串字符并看到 Got packets out of order 消息,则您已连接到该服务。

    如果您有 MySQL 客户端,请使用标准 CLI 命令登录:

    $ mysql -h 172.30.131.89 -u admin -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    
    MySQL [(none)]>

然后,执行以下任务: