CentOS7安裝openshift集群
- OpenShift官網(wǎng):https://www.openshift.com/
- Github:https://github.com/openshift/origin
開(kāi)源容器應(yīng)用程序平臺(tái),Origin是支持OpenShift的上游社區(qū)項(xiàng)目嫉父。圍繞Docker容器打包和Kubernetes容器集群管理的核心構(gòu)建,Origin還增加了應(yīng)用程序生命周期管理功能和DevOps工具汗销。Origin提供了一個(gè)完整的開(kāi)源容器應(yīng)用程序平臺(tái)枕面。
安裝OpenShift Origin,它是Red Hat OpenShift的開(kāi)源版本
- 環(huán)境CentOS7:
Hostname | Role | IP |
---|---|---|
master.aniu.so | Master, etcd, and node | 192.168.0.111 |
node1.aniu.so | Computer Node | 192.168.0.114 |
node2.aniu.so | Computer Node | 192.168.0.115 |
集群配置參考:https://docs.openshift.org/latest/install_config/install/planning.html
配置群集的一些系統(tǒng)要求
- 主節(jié)點(diǎn)至少16G的內(nèi)存
- 在所有節(jié)點(diǎn)上,需要物理卷上的可用空間才能為Docker Direct LVM創(chuàng)建新的卷組徒坡,var目錄至少40G,不然檢測(cè)通不過(guò)
主機(jī)設(shè)置
- 安裝依賴包,關(guān)閉防火墻瘤缩,禁用selinux喇完,添加sysctl net.ipv4.ip_forward=1,所有節(jié)點(diǎn)均執(zhí)行
詳情見(jiàn):https://github.com/openshift/origin/blob/master/docs/cluster_up_down.md#prerequisites
參考:https://docs.openshift.org/latest/install_config/install/host_preparation.html#install-config-install-host-preparation
yum install wget git net-tools bind-utils yum-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct -y
yum install ansible pyOpenSSL -y
- 在所有節(jié)點(diǎn)上剥啤,安裝OpenShift Origin 3.9存儲(chǔ)庫(kù)和Docker锦溪。 接下來(lái),為Docker Direct LVM創(chuàng)建一個(gè)卷組府怯,以便像下面那樣設(shè)置LVM Thinpool刻诊。
# 以master為例,雖有節(jié)點(diǎn)都必須執(zhí)行
[root@master ~]# yum -y install centos-release-openshift-origin37 docker
[root@master ~]# vgcreate centos /dev/sdb1 #筆者vgname為centos
Volume group "centos" successfully created
[root@master ~]# echo VG=centos >> /etc/sysconfig/docker-storage-setup
[root@master ~]# systemctl start docker
[root@master ~]# systemctl enable docker
- 設(shè)置三個(gè)節(jié)點(diǎn)master節(jié)點(diǎn)與其他節(jié)點(diǎn)ssh免密牺丙。方便執(zhí)行ansible-playbook
# 在master節(jié)點(diǎn)上執(zhí)行:
[root@master ~]# ssh-keygen -t rsa
# 創(chuàng)建免密設(shè)置
[root@master ~]# cat /etc/hosts # 參考筆者h(yuǎn)osts则涯,同步hosts到node1,node2
127.0.0.1 localhost localhost.localdomain pinpoint
###########################################
## openshift
192.168.0.113 master.aniu.so
192.168.0.114 node1.aniu.so
192.168.0.115 node2.aniu.so
[root@master ~]# ssh-copy-id master.aniu.so
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
(if you think this is a mistake, you may want to use -f option)
[root@master ~]# ssh-copy-id node1.aniu.so
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
(if you think this is a mistake, you may want to use -f option)
[root@master ~]# ssh-copy-id node2.aniu.so
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
(if you think this is a mistake, you may want to use -f option)
在主節(jié)點(diǎn)上,使用root登錄并運(yùn)行Ansible Playbook以設(shè)置OpenShift群集粟判。
yum -y install atomic-openshift-utils
配置ansible的hosts如下:
[root@master ~]# cat /etc/ansible/hosts
# add follows to the end
[OSEv3:children]
masters
nodes
etcd
[OSEv3:vars]
# admin user created in previous section
ansible_ssh_user=root
openshift_deployment_type=origin
# use HTPasswd for authentication
openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/.htpasswd'}]
openshift_master_default_subdomain=apps.test.aniu.so
# allow unencrypted connection within cluster
openshift_docker_insecure_registries=172.30.0.0/16
[masters]
master.aniu.so openshift_schedulable=true containerized=false
[etcd]
master.aniu.so
[nodes]
# set labels [region: ***, zone: ***] (any name you like)
master.aniu.so openshift_node_labels="{'region': 'infra', 'zone': 'default'}"
node1.aniu.so openshift_node_labels="{'region': 'primary', 'zone': 'east'}" openshift_schedulable=true
node2.aniu.so openshift_node_labels="{'region': 'primary', 'zone': 'west'}" openshift_schedulable=true
# 運(yùn)行deploy_cluster.yml手冊(cè)以啟動(dòng)安裝:
ansible-playbook /usr/share/ansible/openshift-ansible/playbooks/deploy_cluster.yml # 此步驟會(huì)很慢亿昏,筆者大概花了2個(gè)多小時(shí)。浮入。龙优。
- 正常執(zhí)行完成查看狀態(tài)
- 可能會(huì)出現(xiàn)的報(bào)錯(cuò):
Error from server (Forbidden): nodes is forbidden: User "system:anonymous" cannot list nodes at the cluster scope: User "system:anonymous" cannot list all nodes in the cluster
報(bào)錯(cuò)解決:
[root@master ~]# oc login -u system:admin # 使用admin登錄進(jìn)行查看
Logged into "https://master.aniu.so:8443" as "system:admin" using existing credentials.
You have access to the following projects and can switch between them with 'oc project <projectname>':
* default
kube-public
kube-system
logging
management-infra
openshift
openshift-infra
openshift-node
openshift-web-console
Using project "default".
[root@master ~]# oc get nodes
NAME STATUS ROLES AGE VERSION
master.aniu.so Ready master 4h v1.9.1+a0ce1bc657
node1.aniu.so Ready <none> 4h v1.9.1+a0ce1bc657
node2.aniu.so Ready <none> 4h v1.9.1+a0ce1bc657
[root@master ~]# oc get nodes --show-labels=true
NAME STATUS ROLES AGE VERSION LABELS
master.aniu.so Ready master 4h v1.9.1+a0ce1bc657 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master.aniu.so,node-role.kubernetes.io/master=true,region=infra,zone=default
node1.aniu.so Ready <none> 4h v1.9.1+a0ce1bc657 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node1.aniu.so,region=primary,zone=east
node2.aniu.so Ready <none> 4h v1.9.1+a0ce1bc657 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node2.aniu.so,region=primary,zone=west
創(chuàng)建一個(gè)新用戶用來(lái)登錄openshift
- 在master節(jié)點(diǎn)上創(chuàng)建用戶:
[root@master ~]# htpasswd /etc/origin/master/.htpasswd aniu #
- 用任何操作系統(tǒng)用戶登錄,然后登錄OpenShift群集事秀,只需添加一個(gè)HTPasswd用戶
[root@master ~]# oc login
Authentication required for https://master.aniu.so:8443 (openshift)
Username: aniu
Password:
Login successful.
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>
[root@master ~]# oc whoami
aniu
[root@master ~]# oc logout
Logged "aniu" out on "https://master.aniu.so:8443"
- 可以從任何使用Web瀏覽器的客戶端訪問(wèn)管理控制臺(tái)彤断。
[圖片上傳失敗...(image-ad95d1-1527840854860)]
[圖片上傳失敗...(image-f92e1c-1527840854860)]