带你读《云原生应用开发 Operator原理与实践》第一章引言1.2Operator 介绍(五)

(5)  Welcome应用部署

接下来,我们部署前面步骤中更新的Type和 Controller文件,并创建 Welcome类型资源(见代码清单1-15)

$kubectlcreate-fconfig/crd/bases/

$kubectlcreate-fconfig/samples/webapp_v1_welcome.yaml

 

此时,我们通过kubectlgetcrd命令可以看到自定义对象已经生效见代码清单1-16

$kubectlgetcrd

NAME                                      CREATEDAT

crontabs.stable.example.com                                             2021-02-18T06:23:11Zwelcomes.webapp.demo.welcome.domain                                                        2021-03-10T13:06:37Z

通过kubectlgetwelcome命令可以看到创建的welcome对象(见代码清单1-17)。

$kubectlgetwelcomeNAMEAGE


welcome-sample     3s

此时 CRD并不会完成任何工作,只是在ETCD中创建了一条记录,我们需要运行Controller才能帮助我们完成调谐工作并最终达到 welcome定义的状态。

$makerun

以上方式在本地启动控制器,方便调试和验证,最终显示见代码清单   1-18。


2021-03-11T21:04:56.904+0800      INFO    controller-runtime.metrics     metrics

serverisstartingtolisten        {"addr":":8080"}

2021-03-11T21:04:56.904+0800      INFO    setup    startingmanager

2021-03-11T21:04:56.904+0800      INFO    controller-runtime.manager     starting

metricsserver        {"path":"/metrics"}

2021-03-11T21:04:56.905+0800      INFO    controller-runtime.controller

StartingEventSource{"controller":"welcome","source":"kindsource:

/,Kind="}

2021-03-11T21:04:57.005+0800      INFO    controller-runtime.controller

StartingController{"controller":"welcome"}

2021-03-11T21:04:57.005+0800      INFO    controller-runtime.controller

Startingworkers       {"controller":"welcome","workercount":1}

2021-03-11T21:04:57.006+0800INFO    controllers.Welcomereconcilingwelcome

{"welcome":"default/welcome-sample"}

2021-03-11T21:04:57.006+0800INFO   controllers.Welcome   createdeploymentsuccess!

{"welcome":"default/welcome-sample"}

2021-03-11T21:04:57.056+0800INFO    controllers.Welcomecreateservicesuccess!

{"welcome":"default/welcome-sample"}

2021-03-11T21:04:57.056+0800INFO    controllers.Welcomecreatedeployandservice

success!       {"welcome":"default/welcome-sample"}

2021-03-11T21:04:57.056+0800        DEBUGcontroller-runtime.controller

SuccessfullyReconciled       {"controller":"welcome","request":"default/welcome-sample"}

 

此时我们通过代码清单 1-19 验证控制器是否完成对象创建及状态更新。


$kubectlgetdeplo

NAME                        READY    UP-TO-DATE    AVAILABLE    AGE

welcome-sample                 1/1     1            1           3m2s

 

通过代码清单 1-20可以看到,Deployment 已经创建成功,并且达到期望的副本数量。


$kubectlgetsvc

NAME                    TYPE          CLUSTER-IP                        EXTERNAL-IPPORT(S)AGE

kubernetes               ClusterIP      10.96.0.1                         <none>         443/TCP212d

welcome-sample            LoadBalancer10.96.242.198<pending>                 8080:32181/TCP    4m12s

 

通过代码清单1-21可以看到,此时Service已经创建成功,并且分配到集群IP,我们通过集群 IP访问应用查看。

$curl-L10.96.242.198:8080/hello/

<htmlng-app="redis">

<head>

<title>Hello</title>

 

</head>

<body>

<divstyle="width:50%;margin-left:20px">

<h2>Welcome!ThisisanOpetatorDemo</h2>

</div>

</body>

</html>


Hellomyfriends

上一篇:带你读《云原生应用开发 Operator原理与实践》第一章引言1.1云原生介绍(三)


下一篇:带你读《云原生应用开发 Operator原理与实践》第一章引言1.2Operator 介绍(一)