下载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"}
按顺序执行以下命令,完成在mysql项目中部署example-mysql应用。
$ oc new-project helm-mysql-1
$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
"stable" has been added to your repositories
$ helm repo update
$ 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}
$ 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
$ oc get pod
NAME READY STATUS RESTARTS AGE
example-mysql-6d66b99db5-bxrkt 1/1 Running 0 4h21m
$ oc new-project helm-mysql-2
$ git clone https://github.com/liuxiaoyu-git/helm-repo
$ 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}
$ oc get pod
NAME READY STATUS RESTARTS AGE
mysql-mysql-7dd478658f-cxjhh 1/1 Running 0 34m