春江水暖Openshift 4先知-第一篇:終於實現了IaaS和PaaS的彈性統一!

前言:本文僅用於技術談論。本實驗Openshift4.0安裝在AWS上。最終經過配置MachineSet實現IaaS和PaaS統一管理。也就是說,當Openshift集羣性能不足的時候,自動建立aws虛擬機,而且將aws虛擬機加入到計算節點。Openshift4.1將支持基於vSphere虛擬化的彈性伸縮。git


OCP4首頁面:github


圖片

首先部署Web terminal的pod:shell

圖片

圖片

傳遞參數設置版本爲4.0:api

接下來咱們須要建立一個路由,以便咱們能夠從OpenShift外部(即從互聯網)訪問此應用程序。在左側菜單中,選擇「網絡」,而後選擇「路線」。在新窗格中,選擇左上角的「建立router」。 輸入'workshop-terminal'做爲路徑名稱,將主機名和路徑保留爲默認值,從「服務」菜單中的服務列表中選擇「workshop-terminal」,而後選擇「目標端口」中的惟一端口下拉(應該是端口10080  - > 10080),像這樣:網絡

圖片

在右上角,接下來,咱們能夠經過路由的地址訪問終端:
架構

圖片

圖片

查看集羣版本:app

圖片
查看集羣中的Operator類型:ide

圖片

或者更全面地獲取在集羣上運行的運算符列表,以及提供該功能的代碼,文檔和提交的連接以下:
性能

您還能夠將rsh(遠程shell訪問)導入正在運行的Operator,並查看與已安裝的OpenShift版本相關的各類清單:fetch

查看一個operator的具體配置:

sh-4.2# cat  0000_70_operator-marketplace_03_operatorsource.crd.yaml

apiVersion: apiextensions.k8s.io/v1beta1

kind: CustomResourceDefinition

metadata:

  name: operatorsources.marketplace.redhat.com

  annotations:

    displayName: Operator Source

    description: Represents an OperatorSource.

spec:

  group: marketplace.redhat.com

  names:

    kind: OperatorSource

    listKind: OperatorSourceList

    plural: operatorsources

    singular: operatorsource

    shortNames:

    - opsrc

  scope: Namespaced

  version: v1alpha1

  additionalPrinterColumns:

  - name: Type

    type: string

    description: The type of the OperatorSource

    JSONPath: .spec.type

  - name: Endpoint

    type: string

    description: The endpoint of the OperatorSource

    JSONPath: .spec.endpoint

  - name: Registry

    type: string

    description: App registry namespace

    JSONPath: .spec.registryNamespace

  - name: DisplayName

    type: string

    description: Display (pretty) name to indicate the OperatorSource's name

    JSONPath: .spec.displayName

  - name: Publisher

    type: string

    description: Publisher of the OperatorSource

    JSONPath: .spec.publisher

  - name: Status

    type: string

    description: Current status of the OperatorSource

    JSONPath: .status.currentPhase.phase.name

  - name: Message

    type: string

    description: Message associated with the current status

    JSONPath: .status.currentPhase.phase.message

  - name: Age

    type: date

    JSONPath: .metadata.creationTimestamp

  validation:

    openAPIV3Schema:

      properties:

        spec:

          type: object

          description: Spec for an OperatorSource.

          required:

          - type

          - endpoint

          - registryNamespace

          properties:

            type:

              type: string

              description: The type of the OperatorSource

              pattern: 'appregistry'

            endpoint:

              type: string

              description: Points to the remote app registry server from where operator manifests can be fetched.

            registryNamespace:

              type: string

              description: |-

                The namespace in app registry.

                Only operator manifests under this namespace will be visible.

                Please note that this is not a k8s namespace.



擴展OpenShift 4羣集

使用OpenShift 4.0+,咱們如今能夠經過OpenShift自己動態擴展羣集大小。


在本練習中,咱們將手動將工做節點添加到集羣:


若是您還沒有登陸,請轉到OpenShift Web控制檯並使用admin登陸(若是不一樣,則使用您的管理員用戶名)


瀏覽到左側邊欄上的「MachineSet」,而後單擊「MachineSet」。


在Machine Sets頁面上,從Project下拉列表中選擇openshift-machine-api,您應該看到機器集:

經過單擊名稱選擇列表中的一個Machine Sets,例如, 「beta-190305-1-79tf5-worker-us-east-1a」


經過單擊選擇要擴容的節點

此時,您能夠單擊此計算機集顯示中的計算機選項卡,而後查看已分配的計算機。 概述選項卡將通知您機器什麼時候準備就緒。 若是再次單擊左側機器下的機器集,您還將看到集合中機器的狀態:

新機器準備就緒須要幾分鐘。 在後臺,正在配置其餘EC2實例,而後註冊並配置爲參與羣集,

您能夠在Web UI控制檯中以多種方式更改機器集計數,但您也能夠經過使用openshift-machine-api項目中machineset上的oc edit命令經過CLI執行相同的操做 。

 oc edit machineset -n openshift-machine-api

圖片

圖片

若是有指定的配置,OpenShift能夠根據工做負載自動擴展基礎架構。 在開始以前,請確保您的羣集恢復運行三個節點:

圖片

接下來,配置MachineAutoScaler  - 您須要獲取如下YAML文件:

wget https://raw.githubusercontent.com/openshift/training/master/assets/machine-autoscale-example.yaml

[root@client ~]# cat machine-autoscale-example.yaml

kind: List

metadata: {}

apiVersion: v1

items:

- apiVersion: "autoscaling.openshift.io/v1alpha1"

  kind: "MachineAutoscaler"

  metadata:

    generateName: autoscale-<aws-region-az>-

    namespace: "openshift-machine-api"

  spec:

    minReplicas: 1

    maxReplicas: 4

    scaleTargetRef:

      apiVersion: machine.openshift.io/v1beta1

      kind: MachineSet

      name: <clusterid>-worker-<aws-region-az>

- apiVersion: "autoscaling.openshift.io/v1alpha1"

  kind: "MachineAutoscaler"

  metadata:

    generateName: autoscale-<aws-region-az>-

    namespace: "openshift-machine-api"

  spec:

    minReplicas: 1

    maxReplicas: 4

    scaleTargetRef:

      apiVersion: machine.openshift.io/v1beta1

      kind: MachineSet

      name: <clusterid>-worker-<aws-region-az>

- apiVersion: "autoscaling.openshift.io/v1alpha1"

  kind: "MachineAutoscaler"

  metadata:

    generateName: autoscale-<aws-region-az>-

    namespace: "openshift-machine-api"

  spec:

    minReplicas: 1

    maxReplicas: 4

    scaleTargetRef:

      apiVersion: machine.openshift.io/v1beta1

      kind: MachineSet

      name: <clusterid>-worker-<aws-region-az>

[root@client ~]#


修改以下部份內容:

apiVersion: "autoscaling.openshift.io/v1alpha1"
kind: "MachineAutoscaler"
metadata:
 generateName: autoscale-us-east-1a-
 namespace: "openshift-machine-api"
spec:
 minReplicas: 1
 maxReplicas: 4
 scaleTargetRef:
   apiVersion: machine.openshift.io/v1beta1
   kind: MachineSet
   name: beta-190305-1-79tf5-worker-us-east-1a
$ export CLUSTER_NAME=$(oc get machinesets -n openshift-machine-api | awk -F'-worker-' 'NR>1{print $1;exit;}')
$ export REGION_NAME=us-east-1a

$ sed -i s/\<aws-region-az\>/$REGION_NAME/g machine-autoscale-example.yaml
$ sed -i s/\<clusterid\>/$CLUSTER_NAME/g machine-autoscale-example.yaml

您沒必要爲每一個MachineSet定義MachineAutoScaler。 每一個MachineSet對應一個AWS區域/ AZ。 所以,若是沒有多個MachineAutoScalers,您最終可能會在單個AZ中徹底擴展集羣。 若是這就是你所追求的,那很好。 可是,若是AWS在該AZ中存在問題,則存在丟失大部分羣集的風險。

定義ClusterAutoscaler

接下來,咱們須要定義一個ClusterAutoscaler,它爲集羣的自動調整方式配置一些邊界和行爲。 能夠在如下位置找到示例定義文件:


https://raw.githubusercontent.com/openshift/training/master/assets/cluster-autoscaler.yaml


這個定義最多設定爲20個worker,但咱們須要經過咱們的實驗室來減小這種狀況。 先下載該文件:



[root@client ~]#  wget https://raw.githubusercontent.com/openshift/training/master/assets/cluster-autoscaler.yaml

--2019-03-20 04:12:41--  https://raw.githubusercontent.com/openshift/training/master/assets/cluster-autoscaler.yaml

Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.108.133

Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.108.133|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 254 [text/plain]

Saving to: ‘cluster-autoscaler.yaml’


100%[============================================================================================================>] 254         --.-K/s   in 0s


2019-03-20 04:12:41 (11.4 MB/s) - ‘cluster-autoscaler.yaml’ saved [254/254]


[root@client ~]# sed -i s/20/10/g cluster-autoscaler.yaml

[root@client ~]#  oc create -f cluster-autoscaler.yaml

clusterautoscaler.autoscaling.openshift.io/default created

[root@client ~]#

定義一個worker

如下示例YAML文件定義了一個Job:


https://raw.githubusercontent.com/openshift/training/master/assets/job-work-queue.yaml


它將產生羣集沒法處理的大量負載,並將強制自動縮放器採起操做(最多爲ClusterAutoscaler YAML中定義的maxReplicas)。


注意:若是您以前未縮小計算機,則可能有太多容量來觸發自動縮放事件。 在繼續以前,確保您的工人總數不超過3人。


建立一個項目來保存Job的資源,並切換到它:



[root@client ~]#  oc adm new-project autoscale-example && oc project autoscale-example

Created project autoscale-example

Now using project "autoscale-example" on server "https://api.cluster-9fb8.9fb8.sandbox182.opentlc.com:6443".




指定彈性收縮

如今咱們準備建立job,給系統加壓:


[root@client ~]# oc create -n autoscale-example -f https://raw.githubusercontent.com/openshift/training/master/assets/job-work-queue.yaml

job.batch/work-queue-g4zn4 created

圖片

圖片

過一會,查看機器列表,計算節點已經增長了:

圖片

相關文章
相關標籤/搜索