zl程序教程

您现在的位置是:首页 >  其他

当前栏目

把运行在 Docker 容器内的 Microsoft SQL 服务器部署到 SAP Kyma 中

2023-09-14 09:03:10 时间

在阅读这篇文章之前,Jerry 假设您已经读过了这篇在 Docker 里运行 Microsoft SQL 服务器

本地项目地址:C:\Code\referenceCode\SAP Kyma教程例子

参考链接:https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html#42706edb-619b-43f4-9b3e-3179f149e565

secret.yaml

定义了数据库的用户名和密码。

pvc.yaml

定义了一个 PersistentVolume,用于存储数据库的数据。

deployment.yaml

defines the Deployment definition for the MSSQL database as well as a Service used for communication. This definition references both the secret.yaml and pvc.yaml by name.

使用这篇文章如何使用 kubectl 通过命令行的方式操作 SAP Kyma提到的方法,配置好 kubectl 和 SAP Kyma 的连接。

使用命令行创建名为 dev 的 namespace:

kubectl create namespace dev

部署 secret.yaml 和 pvc.yaml:

kubectl -n dev apply -f ./k8s/pvc.yaml

注意,如果遇到下列错误消息:

error: you must be logged in to the server ( the server has asked for the client to provide credentials):

解决办法就是从 Kyma 控制台重新下载一份 kubeconfig:

成功部署 PersistentVolumeClaim:persistentvolumeclaim/mssql-data created

成功部署 secret:

最后使用如下命令,将本地 k8s 文件夹里的 yaml 文件代表的 deployment 资源,部署到 SAP Kyma 上:

部署成功后,使用命令行查看自动生成的 pod 的名称:

我的 pod 名称:mssql-74787d5b48-lr877

Kubernetes provides a port-forward functionality that allows you to connect to resources running in the Kyma runtime locally. This can be useful for development and debugging tasks.

使用如下命令行拿到该 pod 监听的端口号:

kubectl get pod mssql-74787d5b48-lr877 -n dev --template="{{(index (index .spec.containers 0).ports 0).containerPort}}"

得到端口号:1433

使用如下命令为 pod 设置端口转发,即 port forward 功能:

kubectl port-forward mssql-74787d5b48-lr877 -n dev 1433:1433

看到如下输出:

Forwarding from 127.0.0.1:1433 -> 1433
Forwarding from [::1]:1433 -> 1433

接下来,我们就可以在本地,使用 localhost:1433 访问运行在 SAP Kyma 里的数据库了。

sqlcmd -S localhost:1433 -U SA -P Yukon900

使用如下命令找到 pod 里的 container 名称:mssql

kubectl describe pod mssql-74787d5b48-lr877 -n dev

使用命令

kubectl exec -it mssql-74787d5b48-lr877 -n dev -c mssql – bash

需要提前设置环境变量:set KUBECONFIG=C:\app\kubeconfig.yml


更多Jerry的原创文章,尽在:“汪子熙”: