在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
  • 前言 當別人做大數據用Java、Python的時候,我使用.NET做大數據、數據挖掘,這確實是值得一說的事。 寫的並不全面,但都是實際工作中的內容。 .NET在大數據項目中,可以做什麼? 寫腳本(使用控制台程式+頂級語句) 寫工具(使用Winform) 寫介面、寫服務 使用C#寫代碼的優點是什麼? ...
  • 前言 本文寫給想學C#的朋友,目的是以儘快的速度入門 C#好學嗎? 對於這個問題,我以前的回答是:好學!但仔細想想,不是這麼回事,對於新手來說,C#沒有那麼好學。 反而學Java還要容易一些,學Java Web就行了,就是SpringBoot那一套。 但是C#方向比較多,你是學控制台程式、WebAP ...
  • 某一日晚上上線,測試同學在回歸項目黃金流程時,有一個工單項目介面報JSF序列化錯誤,馬上升級對應的client包版本,編譯部署後錯誤消失。 線上問題是解決了,但是作為程式員要瞭解問題發生的原因和本質。但這都是為什麼呢? ...
  • 本文介紹基於Python語言中TensorFlow的Keras介面,實現深度神經網路回歸的方法。 1 寫在前面 前期一篇文章Python TensorFlow深度學習回歸代碼:DNNRegressor詳細介紹了基於TensorFlow tf.estimator介面的深度學習網路;而在TensorFl ...
  • 前段時間因業務需要完成了一個工作流組件的編碼工作。藉著這個機會跟大家分享一下整個創作過程,希望大家喜歡,組件暫且命名為"easyFlowable"。 接下來的文章我將從什麼是工作流、為什麼要自研這個工作流組件、架構設計三個維度跟大家來做個整體介紹。 ...
  • 1 簡介 我們之前使用了dapr的本地托管模式,但在生產中我們一般使用Kubernetes托管,本文介紹如何在GKE(GCP Kubernetes)安裝dapr。 相關文章: dapr本地托管的服務調用體驗與Java SDK的Spring Boot整合 dapr入門與本地托管模式嘗試 2 安裝GKE ...
  • 摘要:在jvm中有很多的參數可以進行設置,這樣可以讓jvm在各種環境中都能夠高效的運行。絕大部分的參數保持預設即可。 本文分享自華為雲社區《為什麼需要對jvm進行優化,jvm運行參數之標準參數》,作者:共飲一杯無。 我們為什麼要對jvm做優化? 在本地開發環境中我們很少會遇到需要對jvm進行優化的需 ...
  • 背景 我們的業務共使用11台(阿裡雲)伺服器,使用SpringcloudAlibaba構建微服務集群,共計60個微服務,全部註冊在同一個Nacos集群 流量轉發路徑: nginx->spring-gateway->業務微服務 使用的版本如下: spring-boot.version:2.2.5.RE ...
  • 基於php+webuploader的大文件分片上傳,帶進度條,支持斷點續傳(刷新、關閉頁面、重新上傳、網路中斷等情況)。文件上傳前先檢測該文件是否已上傳,如果已上傳提示“文件已存在”,如果未上傳則直接上傳。視頻上傳時會根據設定的參數(分片大小、分片數量)進行上傳,上傳過程中會在目標文件夾中生成一個臨 ...
  • 基於php大文件分片上傳至七牛雲,使用的是七牛雲js-sdk V2版本,引入js文件,配置簡單,可以暫停,暫停後支持斷點續傳(刷新、關閉頁面、重新上傳、網路中斷等情況),可以配置分片大小和分片數量,官方文檔https://developer.qiniu.com/kodo/6889/javascrip ...