OpenShift 4.3 之新特性 - 使用Helm部署OpenShift应用

文章目录

  • 下载helm客户端
  • 通过helm在OpenShift上安装部署应用
    • 使用外部Repo安装部署应用
    • 使用本地Repo安装部署应用

在OpenShift 4.3中已经内置了Helm 3.0,我们可以使用Helm Chart部署OpenShift应用。它的使用过程如下:
OpenShift 4.3 之新特性 - 使用Helm部署OpenShift应用_第1张图片

下载helm客户端

下载helm客户端,并查看版本。

$ sudo curl -L https://mirror.openshift.com/pub/openshift-v4/clients/helm/latest/helm-linux-amd64 -o /usr/local/bin/helm
$ sudo chmod +x /usr/local/bin/helm
$ helm version
version.BuildInfo{Version:"v3.0", GitCommit:"b31719aab7963acf4887a1c1e6d5e53378e34d93", GitTreeState:"clean", GoVersion:"go1.13.4"}

通过helm在OpenShift上安装部署应用

使用外部Repo安装部署应用

按顺序执行以下命令,完成在mysql项目中部署example-mysql应用。

  1. 创建项目。
$ oc new-project helm-mysql-1
  1. 为helm增加外部Repo。
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
  1. 更新helm的Repo
$ helm repo update
  1. 根据Repo安装example-mysql应用
$ helm install example-mysql stable/mysql
NAME: example-mysql
LAST DEPLOYED: Mon Mar  2 03:12:52 2020
NAMESPACE: helm-mysql-1
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
example-mysql.helm-mysql-1.svc.cluster.local
  
To get your root password run:
  
    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace helm-mysql-1 example-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
  
To connect to your database:
 
(1). Run an Ubuntu pod that you can use as a client:

    kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
 
(2). Install the mysql client:
  
    $ apt-get update && apt-get install mysql-client -y
 
(3). Connect using the mysql cli, then provide your password:
    $ mysql -h example-mysql -p
 
To connect to your database directly from outside the K8s cluster:
    MYSQL_HOST=127.0.0.1
    MYSQL_PORT=3306
 
    ## Execute the following command to route the connection:
    kubectl port-forward svc/example-mysql 3306
 
    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD} 
  1. 查看helm列表。
$ helm list
NAME          NAMESPACE     REVISION UPDATED                        STATUS   CHART       APP VERSION
example-mysql helm-mysql-11 2019-12-05 15:06:51.379134163 -0500 EST deployed mysql-1.5.0 5.7.27
  1. 查看应用的Pod运行部署状态
$ oc get pod
NAME                             READY   STATUS    RESTARTS   AGE
example-mysql-6d66b99db5-bxrkt   1/1     Running   0          4h21m

使用本地Repo安装部署应用

  1. 创建新项目
$ oc new-project helm-mysql-2
  1. 下载项目Repo到本地
$ git clone https://github.com/liuxiaoyu-git/helm-repo
  1. 根据本地Repo安装mysql应用
$ helm install mysql ./helm-repo/incubator/mysql
NAME: mysql                                                                                                                                      
LAST DEPLOYED: Mon Mar  2 07:02:53 2020                                                                                                          
NAMESPACE: nodejs-ex-k                                                                                                                           
STATUS: deployed                                                                                                                                 
REVISION: 1                                                                                                                                      
TEST SUITE: None                                                                                                                                 
NOTES:                                                                                                                                           
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:                                                          
mysql-mysql.nodejs-ex-k.svc.cluster.local                                                                                                        
                                                                                                                                                 
To get your root password run:                                                                                                                   
                                                                                                                                                 
    MYSQL_ROOT_PASSWORD=$(oc get secret --namespace helm-mysql-2 mysql-mysql -o jsonpath="{.data.database-root-password}" | base64 --decode; echo)
                                                                                                                                                 
To know your database:                                                                                                                           
                                                                                                                                                 
    MYSQL_DATABASE=$(oc get secret --namespace helm-mysql-2 mysql-mysql -o jsonpath="{.data.database-name}" | base64 --decode; echo)              
                                                                                                                                                 
To connect to your database:                                                                                                                     
                                                                                                                                                 
(1). Run an Centos pod that you can use as a client:                                                                                               
                                                                                                                                                 
    oc run -i --rm --tty centos --image=centos/mysql-57-centos7 --restart=Never -- bash -il                                                      
                                                                                                                                                 
(2). Connect using the mysql cli, then provide your password:                                                                                      
    $ mysql -h mysql-mysql.nodejs-ex-k.svc.cluster.local -u root -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE}                                      
                                                                                                                                                 
To connect to your database directly from outside the K8s cluster:                                                                               
    MYSQL_HOST=127.0.0.1                                                                                                                         
    MYSQL_PORT=3306                                                                                                                              
                                                                                                                                                 
    ## Execute the following commands to route the connection:                                                                                    
    export POD_NAME=$(oc get pods --namespace helm-mysql-2 -l "app=mysql-mysql" -o jsonpath="{.items[0].metadata.name}"; echo)                    
    oc port-forward --namespace nodejs-ex-k $POD_NAME 3306:3306                                                                                  
                                                                                                                                                 
    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE}                                                    
  1. 查看应用的Pod运行部署状态
$ oc get pod
NAME                           READY   STATUS    RESTARTS   AGE
mysql-mysql-7dd478658f-cxjhh   1/1     Running   0          34m

你可能感兴趣的:(OpenShift,4,Ops)