OKD部署单节点OpenShift 容器应用平台

OKD部署单节点OpenShift 容器应用平台

嚯嚯嚯www 29 2022-08-26

一、 安装OpenShift

  1. 基础配置&Docker安装

#关闭selinux修改主机名

[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
[root@localhost ~]# reboot
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash

#开启路由转发,启用NetworkManager

[root@master ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
[root@master ~]# sysctl -p
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
[root@master ~]# systemctl start NetworkManager
[root@master ~]# systemctl enable NetworkManager

#配置yum(这里使用本地源),安装所需组件,安装docker

[root@master ~]# yum -y install wget git net-tools bind-utils yum-utils sos psacct kexec-tools bridge-utils bash-completion ansible pyOpenSSL
[root@master ~]# yum -y install docker-ce

49095-gjeg5nvwi9j.png

#Openshift要求docker版本高于1.22
75994-71tylfd55dq.png

#配置docker私有仓库地址,启动docker服务

[root@master ~]# vim /etc/docker/daemon.json
{
   "insecure-registries": ["172.30.0.0/16"]
}
[root@master ~]# systemctl enable docker
[root@master ~]# systemctl restart docker
  1. OKD安装openshift

#解压下载的安装包,将文件夹移动到目录下并重命名短名

[root@master ~]# tar -zxf openshift-origin-server-v3.11.0-0cbc58b-linux-64bit.tar.gz
[root@master ~]# mv openshift-origin-server-v3.11.0-0cbc58b-linux-64bit /opt/openshift

29903-d3r26c4gocu.png

#配置环境变量,并应用
[root@master ~]# echo 'PATH=$PATH:/opt/openshift' >> /etc/profile
[root@master ~]# source /etc/profile
#测试oc
[root@master ~]# oc version
oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth GSSAPI Kerberos SPNEGO
#开始安装openshift,--public-hostname=对外访问的IP
[root@master ~]# oc cluster up --skip-registry-check=true --public-hostname=192.168.1.22

14920-8rjmhihsias.png
安装完成
56642-jjjugjnbng8.png

网页访问https://ip:8443地址,默认账号dev/dev
99217-e0bjy4v874.png

二、 OpenShift使用

在命令行中操作需要登陆操作:
oc login -u system:admin
08530-cf8vstfcnlb.png

#获取node节点

[root@master ~]# oc get nodes
NAME        STATUS    ROLES     AGE       VERSION
localhost   Ready     <none>    45m       v1.11.0+d4cacc0
[root@master ~]# oc cluster status
Web console URL: https://192.168.1.22:8443/console/

Config is at host directory 
Volumes are at host directory 
Persistent volumes are at host directory /root/openshift.local.clusterup/openshift.local.pv
Data will be discarded when cluster is destroyed

在网页中登陆后,右上睑create project创建项目
28169-tae34k3gh08.png

设置名称、显示名称、描述
67178-qemmgvavrqb.png

创建完成即可进入
93076-zp6tyr8pa9f.png

查看目录可以创建的项目
23373-j2o4d8i2flc.png

创建一个mysql服务,点击mysql,next下一步
24316-j4k32y2tzhq.png

配置mysql,设置名称,mysql的用户名和密码,root的密码,创建的库名
这些都作为服务的环境变量
29936-ucj9kuw84pa.png

完成dc创建
28048-l0ae24ynuu.png

主页仪表盘即可查看创建的dc以及自动创建的pod
46017-huh56hwg6t.png

命令行创建dc
#使用创建好的project

[root@master ~]# oc project test
Already on project "test" on server "https://192.168.1.22:8443".
#创建dc,创建同时需要配置环境变量
[root@master ~]# oc new-app -e MYSQL_USER=test -e MYSQL_PASSWORD=000000 -e MYSQL_DATABASE=test_db -e MYSQL_ROOT_PASSWORD=123456 openshift/mysql

终端登陆pod
#获取创建的pods信息

[root@master ~]# oc get pods
NAME                READY     STATUS    RESTARTS   AGE
mysql-tao-1-dphx9   1/1       Running   0          1m

#进入pod的终端,可以使用mysql命令登陆数据库
[root@master ~]# oc rsh mysql-tao-1-dphx9
sh-4.2$ mysql -utest -ptest
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#查看库,环境变量时配置的库叶创建了
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test_db            |
+--------------------+
2 rows in set (0.00 sec)
mysql>

命令行配置环境变量

#查询当前dc的名称
[root@master ~]# oc get dc
NAME        REVISION   DESIRED   CURRENT   TRIGGERED BY
mysql-tao   1          1         1         config,image(mysql:5.7)
#查询当前dc的环境变量参数
[root@master ~]# oc set env dc mysql-tao --list
# deploymentconfigs/mysql-tao, container mysql
# MYSQL_USER from secret mysql-tao, key database-user
# MYSQL_PASSWORD from secret mysql-tao, key database-password
# MYSQL_ROOT_PASSWORD from secret mysql-tao, key database-root-password
# MYSQL_DATABASE from secret mysql-tao, key database-name
#修改dc的环境变量,dc会重新更新创建一个pod
[root@master ~]# oc set env dc mysql-tao MYSQL_PASSWORD=123456 MYSQL_ROOT_PASSWORD=123456
deploymentconfig.apps.openshift.io/mysql-tao updated

存储卷的配置
网页中选择Storage,选择create storage,配置名称,大小
24372-m4q7lv2zt9l.png

进入pod,点击右上角的add strorage
79520-40k8awxjnnw.png

勾选创建的卷,配置挂载点
61225-tnc0gmgc5n.png

OpenShift容器的网络配置我还没整明白……555555