在Ubuntu上安裝OpenShift並使用

来源:https://www.cnblogs.com/larrydpk/archive/2023/01/17/17057088.html
-Advertisement-
Play Games

伺服器信息 在阿裡雲買了個搶占式的伺服器,地區為華南廣州,系統為Ubuntu 20.04,8核16GB。 安裝Docker 命令如下: $ apt-get update -y $ apt-get upgrade -y $ apt-get install -y docker.io 安裝成功後,檢查一下 ...


伺服器信息

在阿裡雲買了個搶占式的伺服器,地區為華南廣州,系統為Ubuntu 20.04,8核16GB。

安裝Docker

命令如下:

$ apt-get update -y
$ apt-get upgrade -y
$ apt-get install -y docker.io

安裝成功後,檢查一下版本:

$ docker version
Client:
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.8
 Git commit:        20.10.7-0ubuntu5~20.04.2
 Built:             Mon Nov  1 00:34:17 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.8
  Git commit:       20.10.7-0ubuntu5~20.04.2
  Built:            Fri Oct 22 00:45:53 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.5-0ubuntu3~20.04.1
  GitCommit:        
 runc:
  Version:          1.0.1-0ubuntu2~20.04.1
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:        

要修改Docker配置文件,讓它可以使用私有的registry:

cat << EOF | sudo tee /etc/docker/daemon.json 
 {
     "insecure-registries" : [ "172.30.0.0/16" ]
 }
EOF

然後重啟一下Docker即可:

systemctl restart docker

安裝OpenShift

下載並解壓對應的可執行文件:

# 下載
$ wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz

# 解壓
$ tar xvf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz 

# 複製到bin目錄
$ cp openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc /usr/local/bin/
$ cp openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/kubectl /usr/local/bin/

# 檢查版本
$ oc version
oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth GSSAPI Kerberos SPNEGO

啟動集群,第一次需要比較長的時候,因為需要下載鏡像:

$ oc cluster up
Getting a Docker client ...
Checking if image openshift/origin-control-plane:v3.11 is available ...
Creating shared mount directory on the remote host ...
Determining server IP ...
Checking if OpenShift is already running ...
Checking for supported Docker version (=>1.22) ...
Checking if insecured registry is configured properly in Docker ...
Checking if required ports are available ...
Checking if OpenShift client is configured properly ...
Checking if image openshift/origin-control-plane:v3.11 is available ...
Starting OpenShift using openshift/origin-control-plane:v3.11 ...
I0301 22:24:39.111730   51771 flags.go:30] Running "create-kubelet-flags"
I0301 22:24:39.541760   51771 run_kubelet.go:49] Running "start-kubelet"
I0301 22:24:39.624336   51771 run_self_hosted.go:181] Waiting for the kube-apiserver to be ready ...
I0301 22:25:30.631581   51771 interface.go:26] Installing "kube-proxy" ...
I0301 22:25:30.631597   51771 interface.go:26] Installing "kube-dns" ...
I0301 22:25:30.631604   51771 interface.go:26] Installing "openshift-service-cert-signer-operator" ...
I0301 22:25:30.631609   51771 interface.go:26] Installing "openshift-apiserver" ...
I0301 22:25:30.631624   51771 apply_template.go:81] Installing "openshift-apiserver"
I0301 22:25:30.631673   51771 apply_template.go:81] Installing "kube-dns"
I0301 22:25:30.631682   51771 apply_template.go:81] Installing "openshift-service-cert-signer-operator"
I0301 22:25:30.631689   51771 apply_template.go:81] Installing "kube-proxy"
I0301 22:25:31.680155   51771 interface.go:41] Finished installing "kube-proxy" "kube-dns" "openshift-service-cert-signer-operator" "openshift-apiserver"
I0301 22:29:04.695159   51771 run_self_hosted.go:242] openshift-apiserver available
I0301 22:29:04.695183   51771 interface.go:26] Installing "openshift-controller-manager" ...
I0301 22:29:04.695201   51771 apply_template.go:81] Installing "openshift-controller-manager"
I0301 22:29:05.924403   51771 interface.go:41] Finished installing "openshift-controller-manager"
Adding default OAuthClient redirect URIs ...
Adding registry ...
Adding router ...
Adding centos-imagestreams ...
Adding sample-templates ...
Adding persistent-volumes ...
Adding web-console ...
I0301 22:29:05.934015   51771 interface.go:26] Installing "openshift-image-registry" ...
I0301 22:29:05.934027   51771 interface.go:26] Installing "openshift-router" ...
I0301 22:29:05.934034   51771 interface.go:26] Installing "centos-imagestreams" ...
I0301 22:29:05.934039   51771 interface.go:26] Installing "sample-templates" ...
I0301 22:29:05.934045   51771 interface.go:26] Installing "persistent-volumes" ...
I0301 22:29:05.934050   51771 interface.go:26] Installing "openshift-web-console-operator" ...
I0301 22:29:05.934129   51771 interface.go:26] Installing "sample-templates/mongodb" ...
I0301 22:29:05.934141   51771 apply_list.go:67] Installing "centos-imagestreams"
I0301 22:29:05.934172   51771 apply_list.go:67] Installing "sample-templates/mongodb"
I0301 22:29:05.934145   51771 interface.go:26] Installing "sample-templates/mysql" ...
I0301 22:29:05.934296   51771 interface.go:26] Installing "sample-templates/cakephp quickstart" ...
I0301 22:29:05.934306   51771 interface.go:26] Installing "sample-templates/django quickstart" ...
I0301 22:29:05.934315   51771 interface.go:26] Installing "sample-templates/rails quickstart" ...
I0301 22:29:05.934326   51771 interface.go:26] Installing "sample-templates/mariadb" ...
I0301 22:29:05.934335   51771 interface.go:26] Installing "sample-templates/postgresql" ...
I0301 22:29:05.934343   51771 interface.go:26] Installing "sample-templates/dancer quickstart" ...
I0301 22:29:05.934351   51771 interface.go:26] Installing "sample-templates/nodejs quickstart" ...
I0301 22:29:05.934360   51771 interface.go:26] Installing "sample-templates/jenkins pipeline ephemeral" ...
I0301 22:29:05.934375   51771 interface.go:26] Installing "sample-templates/sample pipeline" ...
I0301 22:29:05.934409   51771 apply_list.go:67] Installing "sample-templates/sample pipeline"
I0301 22:29:05.934539   51771 apply_list.go:67] Installing "sample-templates/mysql"
I0301 22:29:05.934635   51771 apply_list.go:67] Installing "sample-templates/cakephp quickstart"
I0301 22:29:05.934722   51771 apply_list.go:67] Installing "sample-templates/dancer quickstart"
I0301 22:29:05.934724   51771 apply_list.go:67] Installing "sample-templates/nodejs quickstart"
I0301 22:29:05.934748   51771 apply_list.go:67] Installing "sample-templates/jenkins pipeline ephemeral"
I0301 22:29:05.934772   51771 apply_list.go:67] Installing "sample-templates/mariadb"
I0301 22:29:05.934796   51771 apply_list.go:67] Installing "sample-templates/django quickstart"
I0301 22:29:05.934815   51771 apply_list.go:67] Installing "sample-templates/rails quickstart"
I0301 22:29:05.934343   51771 apply_template.go:81] Installing "openshift-web-console-operator"
I0301 22:29:05.934826   51771 apply_list.go:67] Installing "sample-templates/postgresql"
I0301 22:29:08.010606   51771 interface.go:41] Finished installing "sample-templates/mongodb" "sample-templates/mysql" "sample-templates/cakephp quickstart" "sample-templates/django quickstart" "sample-templates/rails quickstart" "sample-templates/mariadb" "sample-templates/postgresql" "sample-templates/dancer quickstart" "sample-templates/nodejs quickstart" "sample-templates/jenkins pipeline ephemeral" "sample-templates/sample pipeline"
I0301 22:29:50.500686   51771 interface.go:41] Finished installing "openshift-image-registry" "openshift-router" "centos-imagestreams" "sample-templates" "persistent-volumes" "openshift-web-console-operator"
Login to server ...
Creating initial project "myproject" ...
Server Information ...
OpenShift server started.

The server is accessible via web console at:
    https://127.0.0.1:8443

You are logged in as:
    User:     developer
    Password: <any value>

To login as administrator:
    oc login -u system:admin

登陸:

$ oc login -u system:admin

查看命令空間:

 # oc get ns
NAME                            STATUS    AGE
default                         Active    6m
kube-dns                        Active    6m
kube-proxy                      Active    6m
kube-public                     Active    6m
kube-system                     Active    6m
myproject                       Active    2m
openshift                       Active    3m
openshift-apiserver             Active    6m
openshift-controller-manager    Active    3m
openshift-core-operators        Active    6m
openshift-infra                 Active    6m
openshift-node                  Active    3m
openshift-service-cert-signer   Active    6m
openshift-web-console           Active    3m

發現與kubectl差不多。

查看所有Pods如下:

$ oc get pods --all-namespaces
NAMESPACE                       NAME                                                      READY     STATUS      RESTARTS   AGE
default                         docker-registry-1-72zc5                                   1/1       Running     0          5m
default                         persistent-volume-setup-75s9s                             0/1       Completed   0          6m
default                         router-1-nglvw                                            1/1       Running     0          6m
kube-dns                        kube-dns-zqs5d                                            1/1       Running     0          9m
kube-proxy                      kube-proxy-p75mh                                          1/1       Running     0          9m
kube-system                     kube-controller-manager-localhost                         1/1       Running     0          9m
kube-system                     kube-scheduler-localhost                                  1/1       Running     0          9m
kube-system                     master-api-localhost                                      1/1       Running     0          8m
kube-system                     master-etcd-localhost                                     1/1       Running     0          8m
openshift-apiserver             openshift-apiserver-4rwzd                                 1/1       Running     0          9m
openshift-controller-manager    openshift-controller-manager-wvwkw                        1/1       Running     0          6m
openshift-core-operators        openshift-service-cert-signer-operator-6d477f986b-rkcww   1/1       Running     0          9m
openshift-core-operators        openshift-web-console-operator-664b974ff5-vtwm8           1/1       Running     0          6m
openshift-service-cert-signer   apiservice-cabundle-injector-8ffbbb6dc-6lkvl              1/1       Running     0          7m
openshift-service-cert-signer   service-serving-cert-signer-668c45d5f-qjwkj               1/1       Running     0          7m
openshift-web-console           webconsole-c877c8b45-m5hpx                                1/1       Running     0          5m

$ kubectl get pods --all-namespaces
NAMESPACE                       NAME                                                      READY     STATUS      RESTARTS   AGE
default                         docker-registry-1-72zc5                                   1/1       Running     0          5m
default                         persistent-volume-setup-75s9s                             0/1       Completed   0          6m
default                         router-1-nglvw                                            1/1       Running     0          5m
kube-dns                        kube-dns-zqs5d                                            1/1       Running     0          8m
kube-proxy                      kube-proxy-p75mh                                          1/1       Running     0          8m
kube-system                     kube-controller-manager-localhost                         1/1       Running     0          9m
kube-system                     kube-scheduler-localhost                                  1/1       Running     0          9m
kube-system                     master-api-localhost                                      1/1       Running     0          8m
kube-system                     master-etcd-localhost                                     1/1       Running     0          8m
openshift-apiserver             openshift-apiserver-4rwzd                                 1/1       Running     0          8m
openshift-controller-manager    openshift-controller-manager-wvwkw                        1/1       Running     0          6m
openshift-core-operators        openshift-service-cert-signer-operator-6d477f986b-rkcww   1/1       Running     0          8m
openshift-core-operators        openshift-web-console-operator-664b974ff5-vtwm8           1/1       Running     0          6m
openshift-service-cert-signer   apiservice-cabundle-injector-8ffbbb6dc-6lkvl              1/1       Running     0          7m
openshift-service-cert-signer   service-serving-cert-signer-668c45d5f-qjwkj               1/1       Running     0          7m
openshift-web-console           webconsole-c877c8b45-m5hpx                                1/1       Running     0          5m

訪問Dashboard

地址為:https://8.134.68.154:8443/console

但是訪問會失敗,會重定向到127.0.0.1,解決方案如下:

$ oc cluster down
$ rm -rf ./openshift.local.clusterup/
$ oc cluster up --public-hostname=8.134.68.154

重啟後,再訪問就可以了。

oc常用命令

# 登陸
oc login -u system -p admin https://8.134.68.154:8443
oc login -u developer -p pkslow https://8.134.68.154:8443
oc login -u=<username> -p=<password> --server=<your-openshift-server> --insecure-skip-tls-verify

# 切換project
oc project <myproject>
oc login -n <myproject>

# 創建資源
oc create -f myobject.yaml -n <myproject>

oc create configmap propsfilecm --from-file=application.properties
oc set volumes dc/myapp --add --overwrite=true --name=configmap-volume --mount-path=/data -t configmap --configmap-name=propsfilecm
 
oc create secret generic oia-secret --from-literal=username=myuser --from-literal=password=mypassword
oc set volumes dc/myapp --add --name=secret-volume --mount-path=/opt/app-root/ --secret-name=oia-secret

# 更新
oc patch svc mysvc --type merge --patch '{"spec":{"ports":[{"port": 8080, "targetPort": 5000 }]}}'

# 調試訪問
oc exec <mypod> cat /opt/app-root/myapp.config
oc rsh <mypod
oc debug dc <mydc>

# 伸縮
oc scale dc <mydc> --replicas=5
oc autoscale dc/app-cli --min 2 --max 5 --cpu-percent=75

# 其它
oc whoami
oc status
oc logs pod <mypod>
oc get pods --all-namespaces
oc describe pod <mypod>
oc get services --sort-by=.metadata.name
oc delete all -l app=tomcat
oc delete pod <mypod> --grace-period=0
oc export bc,dc,is,svc --as-template=myapp.yaml

用到的Images:

# docker images
REPOSITORY                                     TAG       IMAGE ID       CREATED        SIZE
openshift/origin-node                          v3.11     3f7a62b09e77   3 months ago   1.2GB
openshift/origin-control-plane                 v3.11     6608ab37a132   3 months ago   839MB
openshift/origin-haproxy-router                v3.11     ecaa11886824   3 months ago   417MB
openshift/origin-deployer                      v3.11     d35bd5080535   3 months ago   390MB
openshift/origin-hyperkube                     v3.11     0cfb433fadc5   3 months ago   515MB
openshift/origin-cli                           v3.11     33db4aca59ae   3 months ago   390MB
openshift/origin-hypershift                    v3.11     9e866d795822   3 months ago   556MB
openshift/origin-pod                           v3.11     09e1f40f223e   3 months ago   267MB
openshift/origin-docker-registry               v3.11     9dffb2abf1dd   3 years ago    310MB
openshift/origin-web-console                   v3.11     be30b6cce5fa   3 years ago    339MB
openshift/origin-service-serving-cert-signer   v3.11     47dadf9d43b6   3 years ago    276MB

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Spring6 Spring項目的創建 打開IDEA,新建一個maven項目 在maven項目中引入spring的倉庫和依賴 <repositories> <repository> <id>repository.spring.milestone</id> <name>Spring Milestone ...
  • 2023-01-17 一、Spring中的註解 1、使用註解的原因 (1)使用註解將對象裝配到IOC容器中 (2)使用註解管理對象之間依賴關係(自動裝配) 2、Spring中裝配對象的註解 (1)@Component 標識一個受Spring IOC容器管理的普通組件 (2)@Repository 標 ...
  • 好久沒有更新文章了,高齡開發沒什麼技術,去了外包公司後沒怎麼更新文章了。今天分享下統一處理starter,相信開發web系統的時候都是會涉及到前後端的交互,而後端返回數據的時候一般都會統一封裝一個返回對象和統一處理異常,一般情況下都是在controller的每個方法中調用封裝的對象,把相應的數據塞到 ...
  • 2023-01-17 一、Spring管理druid步驟 (1)導入jar包 <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <arti ...
  • 抽獎程式 ''' 抽獎程式 使用時可以修改嘉賓名單,然後單機‘開始’和‘停止’按鈕 來控制界面上名單的滾動實現抽獎功能,涉及的模塊主要 有多線程 ''' import itertools import random import threading import time import tkinte ...
  • 摘要:本文主要講解圖像局部直方圖均衡化和自動色彩均衡化處理。這些演算法可以廣泛應用於圖像增強、圖像去噪、圖像去霧等領域。 本文分享自華為雲社區《[Python從零到壹] 五十四.圖像增強及運算篇之局部直方圖均衡化和自動色彩均衡化處理》,作者: eastmount。 一.局部直方圖均衡化 前文通過調用O ...
  • 簡介 限流顧名思義是對流量大小進行限制,防止請求數量超過系統的負載能力,導致系統崩潰,起到保護作用。 現實生活中限流也隨處可見,節假日出門旅行的人數會劇增,對於旅游景點來說往往會不堪重負,如果不進行人數控制,對整個景點的壓力會非常大,游客的體驗也會非常差,還容易出現安全事故等危險。 同樣的在一線城市 ...
  • 轉載:https://blog.csdn.net/tslx1020/article/details/128250777 1、spawn - 冷啟動 frida-trace -U -f com.apple.ExampleCode -m “+[NSURL URLWithString:]" 2、attac ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...