Openshift:可靠的Kubernetes发行版

企业版 OpenShift 4.3在线安装

2020-03-03  本文已影响0人  ragpo

概述

在去年 OpenShift 4.1 刚刚出来折腾了好久,坑挺多的,今天安装4.3明显坑少了很多,基本没什么坑,就是基础环境的准备花了挺多时间,做个记录。

安装环境介绍

创建一台基础架构节点,我使用rhel7.6;另外创建6台虚拟机,不需要指定系统文件,8C16G100G硬盘。

基础架构节点:主要有负载均衡、Apache、DNS,以及定义集群的相关文件生成和存放的位置。
bootstrap节点:一个引导节点,会临时生成一个kubernetes集群,负责openshift集群的安装,openshift安装好后,最后kubernetes集群会消失,随后这个节点也没用了。
master节点:与ocp3一样。
work节点: 与ocp3一样,不过router相关组件也运行在这上面,没有了infra这种角色的节点。

一台基础架构节点:172.31.20.100
一台bootstrap节点:172.31.20.101
三台master节点:172.31.20.102-104
两台worker节点:172.31.20.105-106
网关:172.31.20.254
DNS Server:172.31.0.121

基础架构节点

基础架构节点我使用 GitHub 上一个大神准备工具进行搭建,也供我们参考学习一下如何准备基础架构环境:
https://github.com/RedHatOfficial/ocp4-helpernode

在基础架构节点上安装相关环境

注意要使用新版本的ansible,我使用的是2.9.6,否则ansible会报错ssh-key生成的问题。

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm
yum -y install ansible git
git clone https://github.com/RedHatOfficial/ocp4-helpernode
cd ocp4-helpernode
cp docs/examples/vars.yaml .
---
disk: sda
helper:
  name: "helper"
  ipaddr: "172.31.20.100"
dns:
  domain: "poc.com"
  clusterid: "ocp4"
  forwarder1: "172.31.0.121"
  forwarder2: "8.8.4.4"
dhcp:
  router: "172.31.20.254"
  bcast: "172.31.20.255"
  netmask: "255.255.255.0"
  poolstart: "172.31.20.101"
  poolend: "172.31.20.109"
  ipid: "172.31.20.0"
  netmaskid: "255.255.255.0"
bootstrap:
  name: "bootstrap"
  ipaddr: "172.31.20.101"
  macaddr: "00:50:56:b7:fa:e1"
masters:
  - name: "master00"
    ipaddr: "172.31.20.102"
    macaddr: "00:50:56:b7:87:b4"
  - name: "master01"
    ipaddr: "172.31.20.103"
    macaddr: "00:50:56:b7:87:95"
  - name: "master02"
    ipaddr: "172.31.20.104"
    macaddr: "00:50:56:b7:a8:32"
workers:
  - name: "worker00"
    ipaddr: "172.31.20.105"
    macaddr: "00:50:56:b7:db:1e"
  - name: "worker01"
    ipaddr: "172.31.20.106"
    macaddr: "00:50:56:b7:29:74"
ocp_bios: "https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.3/4.3.8/rhcos-4.3.8-x86_64-metal.x86_64.raw.gz"
ocp_initramfs: "https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.3/4.3.8/rhcos-4.3.8-x86_64-installer-initramfs.x86_64.img"
ocp_install_kernel: "https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.3/4.3.8/rhcos-4.3.8-x86_64-installer-kernel-x86_64"
ocp_client: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.3.8/openshift-client-linux-4.3.8.tar.gz"
ocp_installer: "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/4.3.8/openshift-install-linux-4.3.8.tar.gz"
mkdir -p /var/www/html/install/
mkdir -p /var/lib/tftpboot/rhcos/
cp openshift-client-linux-4.3.8.tar.gz /usr/local/src/openshift-client-linux.tar.gz
cp openshift-install-linux-4.3.8.tar.gz /usr/local/src/openshift-install-linux.tar.gz
cp rhcos-4.3.8-x86_64-metal.x86_64.raw.gz /var/www/html/install/bios.raw.gz
cp rhcos-4.3.8-x86_64-installer-initramfs.x86_64.img /var/lib/tftpboot/rhcos/initramfs.img
cp rhcos-4.3.8-x86_64-installer-kernel-x86_64 /var/lib/tftpboot/rhcos/kernel
ansible-playbook -e @vars.yaml tasks/main.yml
/usr/local/bin/helpernodecheck
Usage:
helpernodecheck {dns-masters|dns-workers|dns-etcd|dns-other|install-info|haproxy|services|nfs-info}
mkdir ~/ocp4
cd ~/ocp4
mkdir -p ~/.openshift
mkdir -p ~/.openshift

现在的ansible会帮助我们创建密钥文件,也可以关闭:

ls -1 ~/.ssh/helper_rsa
cd ~/ocp4
cat <<EOF > install-config.yaml
apiVersion: v1
baseDomain: poc.com
compute:
- hyperthreading: Enabled
  name: worker
  replicas: 0
controlPlane:
  hyperthreading: Enabled
  name: master
  replicas: 3
metadata:
  name: ocp4
networking:
  clusterNetworks:
  - cidr: 10.254.0.0/16
    hostPrefix: 24
  networkType: OpenShiftSDN
  serviceNetwork:
  - 172.30.0.0/16
platform:
  none: {}
pullSecret: '$(< ~/.openshift/pull-secret)'
sshKey: '$(< ~/.ssh/helper_rsa.pub)'
EOF
openshift-install create manifests
sed -i 's/mastersSchedulable: true/mastersSchedulable: false/g' manifests/cluster-scheduler-02-config.yml
openshift-install create ignition-configs
cp ~/ocp4/*.ign /var/www/html/ignition/
restorecon -vR /var/www/html/
chmod o+r /var/www/html/ignition/*.ign
openshift-install wait-for bootstrap-complete --log-level debug

漫长的等待,等待的过程中做些啥呢?

ssh core@bootstrap
journalctl -b -f -u bootkube.service
sudo podman images
sudo podman ps
sudo crictl ps
sudo crictl images
sudo su -

安装过程中其实有很多报错,但是那些报错是因为镜像没有拉取到,容器没有起来,对应的服务没有起来导致的报错,只需要等待就可以了,但是前提是得你的网络还不错。

安装结束后

export KUBECONFIG=/root/ocp4/auth/kubeconfig
# 或
cp ~/ocp4/auth/kubeconfig ~/.kube/config
oc get csr
oc get csr --no-headers | awk '{print $1}' | xargs oc adm certificate approve
oc get csr | grep 'system:node'
helpernodecheck nfs-setup
oc patch configs.imageregistry.operator.openshift.io cluster --type merge --patch '{"spec":{"managementState":"Managed"}}'
oc patch configs.imageregistry.operator.openshift.io/cluster --type merge -p '{"spec":{"defaultRoute":true}}'
$ oc edit configs.imageregistry.operator.openshift.io

storage:
  pvc:
    claim:
oc get clusteroperator image-registry
oc get pvc --all-namespaces
openshift-install wait-for install-complete

参考链接

https://github.com/RedHatOfficial/ocp4-helpernode/blob/master/docs/quickstart.md

上一篇下一篇

猜你喜欢

热点阅读