Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#134 from alandtsang/cronjob-tutori…
Browse files Browse the repository at this point in the history
…al/running

翻译 1.9 Running and deploying the controller
  • Loading branch information
mergify[bot] committed Jul 28, 2020
2 parents 3134547 + f0e552e commit ce0b8cd
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions docs/book/src/cronjob-tutorial/running.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
# Running and deploying the controller
# 运行和部署 controller

To test out the controller, we can run it locally against the cluster.
Before we do so, though, we'll need to install our CRDs, as per the [quick
start](/quick-start.md). This will automatically update the YAML
manifests using controller-tools, if needed:
要测试 controller,我们可以在集群本地运行它。不过,在开始之前,我们需要按照 [快速入门](/quick-start.md) 安装 CRD。如果需要,将使用 controller-tools 自动更新 YAML 清单:

```bash
make install
```

Now that we've installed our CRDs, we can run the controller against our
cluster. This will use whatever credentials that we connect to the
cluster with, so we don't need to worry about RBAC just yet.
现在我们已经安装了 CRD,在集群上运行 controller 了。这将使用与集群连接所用的任何凭据,因此我们现在不必担心 RBAC。

<aside class="note">

<h1>Running webhooks locally</h1>
<h1>本地运行 webhooks</h1>

If you want to run the webhooks locally, you'll have to generate
certificates for serving the webhooks, and place them in the right
directory (`/tmp/k8s-webhook-server/serving-certs/tls.{crt,key}`, by
default).
如果您想在本地运行 webhooks,必须为 webhooks 服务生成证书,并将它们放在正确的目录中(默认 `/tmp/k8s-webhook-server/serving-certs/tls.{crt,key}`)。

If you're not running a local API server, you'll also need to figure out
how to proxy traffic from the remote cluster to your local webhook server.
For this reason, we generally recommend disabling webhooks when doing
your local code-run-test cycle, as we do below.
如果您未运行本地 API server,则还需要弄清楚如何将流量从远程群集代理到本地 Webhook 服务器。因此,我们通常建议在执行本地 code-run-test 时禁用 webhooks,如下所示。

</aside>

In a separate terminal, run
在单独的终端中运行

```bash
make run ENABLE_WEBHOOKS=false
```

You should see logs from the controller about starting up, but it won't do
anything just yet.
您应该会看到 controller 关于启动的日志,但它还没有做任何事情。

At this point, we need a CronJob to test with. Let's write a sample to
`config/samples/batch_v1_cronjob.yaml`, and use that:
此时,我们需要一个 CronJob 进行测试。让我们写一个样例到 `config/samples/batch_v1_cronjob.yaml`,并使用:

```yaml
{{#include ./testdata/project/config/samples/batch_v1_cronjob.yaml}}
Expand All @@ -49,21 +36,18 @@ At this point, we need a CronJob to test with. Let's write a sample to
kubectl create -f config/samples/batch_v1_cronjob.yaml
```

At this point, you should see a flurry of activity. If you watch the
changes, you should see your cronjob running, and updating status:
此时,您应该看到一系列的活动。如果看到变更,则应该看到您的 cronjob 正在运行,并且正在更新状态:

```bash
kubectl get cronjob.batch.tutorial.kubebuilder.io -o yaml
kubectl get job
```

Now that we know it's working, we can run it in the cluster. Stop the
`make run` invocation, and run
现在我们知道它正在工作,我们可以在集群中运行它。停止 `make run` 调用,然后运行

```bash
make docker-build docker-push IMG=<some-registry>/<project-name>:tag
make deploy IMG=<some-registry>/<project-name>:tag
```

If we list cronjobs again like we did before, we should see the controller
functioning again!
如果像以前一样再次列出 cronjobs,我们应该会看到控制器再次运行!

0 comments on commit ce0b8cd

Please sign in to comment.