环境:OCP 3.4
本实验全部材料来自我的同事陈耿,在此表示感谢!
这次不从 OpenShift 控制台,也不从命令行,而是从 Eclipse 连接 OpenShift 创建 mysql 应用。
1. 右键项目名称 applications -> New -> Application...
输入 mysql,选择 mysql-empemeral
输入 MYSQL_USER:dev,MYSQL_PASSWORD:welcome1
运行起来后,查看 mysql service IP 地址:172.30.151.238,并记下。
2. 访问 mywebsql 应用
根据之前创建的 mysql 应用,输入连接信息:
输入如下 SQL 语句:
create table office (id int(2) primary key auto_increment, country char(25), city char(25), contact char(25));
insert into office (country, city, contact) values ('China', 'Beijing','cn@wbank.com');
insert into office (country, city, contact) values ('India', 'Armrisar','in@wbank.com');
insert into office (country, city, contact) values ('Malaysia', 'Penggang','my@wbank.com');
insert into office (country, city, contact) values ('Sir Lanka', 'Galle','lk@wbank.com');
insert into office (country, city, contact) values ('Japan', 'Matsusaka','jp@wbank.com');
insert into office (country, city, contact) values ('Austria', 'Salzburg','at@wbank.com');
insert into office (country, city, contact) values ('Belgium', 'Antpur','be@wbank.com');
commit;
3. 访问 mybank 应用,点击服务网点,页面报错
怀疑是环境变量设置的不对,检查 mysql 暴露的环境变量
oc process --parameters mysql-ephemeral -n openshift
NAME DESCRIPTION GENERATOR VALUE
MEMORY_LIMIT Maximum amount of memory the container can use. 512Mi
NAMESPACE The OpenShift Namespace where the ImageStream resides. openshift
DATABASE_SERVICE_NAME The name of the OpenShift Service exposed for the database. mysql
MYSQL_USER Username for MySQL user that will be used for accessing the database. expression user[A-Z0-9]{3}
MYSQL_PASSWORD Password for the MySQL connection user. expression [a-zA-Z0-9]{16}
MYSQL_DATABASE Name of the MySQL database accessed. sampledb
MYSQL_VERSION Version of MySQL image to be used (5.5, 5.6 or latest). 5.6
没有看到我希望的环境变量,我需要找的环境变量是 mysql service 暴露出来的 IP 地址和端口
进入 mybank 应用 pod 查看
oc get pods
oc rsh mybank-4-cwcgs
sh-4.2$ env | grep -i MYSQL
MYSQL_PORT_3306_TCP_PORT=3306
MYSQL_PORT_3306_TCP=tcp://172.30.151.238:3306
MYSQL_SERVICE_PORT_MYSQL=3306
MYSQL_PORT_3306_TCP_PROTO=tcp
MYSQL_PORT_3306_TCP_ADDR=172.30.151.238
MYSQL_SERVICE_PORT=3306
MYSQL_PORT=tcp://172.30.151.238:3306
MYSQL_SERVICE_HOST=172.30.151.238
检查程序代码,果然写错了,修改,提交。
4. 访问 mybank 应用,这次成功了!
如果有错,执行以下命令清除,然后重做
oc delete svc/mysql dc/mysql
oc delete secret mysql
本实验全部材料来自我的同事陈耿,在此表示感谢!
这次不从 OpenShift 控制台,也不从命令行,而是从 Eclipse 连接 OpenShift 创建 mysql 应用。
1. 右键项目名称 applications -> New -> Application...
输入 mysql,选择 mysql-empemeral
输入 MYSQL_USER:dev,MYSQL_PASSWORD:welcome1
运行起来后,查看 mysql service IP 地址:172.30.151.238,并记下。
2. 访问 mywebsql 应用
根据之前创建的 mysql 应用,输入连接信息:
输入如下 SQL 语句:
create table office (id int(2) primary key auto_increment, country char(25), city char(25), contact char(25));
insert into office (country, city, contact) values ('China', 'Beijing','cn@wbank.com');
insert into office (country, city, contact) values ('India', 'Armrisar','in@wbank.com');
insert into office (country, city, contact) values ('Malaysia', 'Penggang','my@wbank.com');
insert into office (country, city, contact) values ('Sir Lanka', 'Galle','lk@wbank.com');
insert into office (country, city, contact) values ('Japan', 'Matsusaka','jp@wbank.com');
insert into office (country, city, contact) values ('Austria', 'Salzburg','at@wbank.com');
insert into office (country, city, contact) values ('Belgium', 'Antpur','be@wbank.com');
commit;
3. 访问 mybank 应用,点击服务网点,页面报错
怀疑是环境变量设置的不对,检查 mysql 暴露的环境变量
oc process --parameters mysql-ephemeral -n openshift
NAME DESCRIPTION GENERATOR VALUE
MEMORY_LIMIT Maximum amount of memory the container can use. 512Mi
NAMESPACE The OpenShift Namespace where the ImageStream resides. openshift
DATABASE_SERVICE_NAME The name of the OpenShift Service exposed for the database. mysql
MYSQL_USER Username for MySQL user that will be used for accessing the database. expression user[A-Z0-9]{3}
MYSQL_PASSWORD Password for the MySQL connection user. expression [a-zA-Z0-9]{16}
MYSQL_DATABASE Name of the MySQL database accessed. sampledb
MYSQL_VERSION Version of MySQL image to be used (5.5, 5.6 or latest). 5.6
没有看到我希望的环境变量,我需要找的环境变量是 mysql service 暴露出来的 IP 地址和端口
进入 mybank 应用 pod 查看
oc get pods
oc rsh mybank-4-cwcgs
sh-4.2$ env | grep -i MYSQL
MYSQL_PORT_3306_TCP_PORT=3306
MYSQL_PORT_3306_TCP=tcp://172.30.151.238:3306
MYSQL_SERVICE_PORT_MYSQL=3306
MYSQL_PORT_3306_TCP_PROTO=tcp
MYSQL_PORT_3306_TCP_ADDR=172.30.151.238
MYSQL_SERVICE_PORT=3306
MYSQL_PORT=tcp://172.30.151.238:3306
MYSQL_SERVICE_HOST=172.30.151.238
检查程序代码,果然写错了,修改,提交。
4. 访问 mybank 应用,这次成功了!
如果有错,执行以下命令清除,然后重做
oc delete svc/mysql dc/mysql
oc delete secret mysql
没有评论:
发表评论