一些问题及解答

问题及解答

  1. kubectl proxy 命令及其含义,如何通过 proxy 访问 kubernetes 集群?

    Creates a proxy server or application-level gateway between localhost and the Kubernetes API Server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote kubernetes API Server port, except for the path matching the static content path.

    在本地主机和 Kubernetes API 服务器之间创建代理服务器或应用程序级网关。它还允许通过指定的 HTTP 路径提供静态内容。 除了与静态内容路径匹配的路径之外,所有传入的数据都通过一个端口进入并转发到远程 kubernetes API Server 端口。

    kubectl proxy --port=8080

    ```json

    获取 API 版本

    curl http://localhost:8080/api/

    { "kind": "APIVersions", "versions": [ "v1" ], "serverAddressByClientCIDRs": [ { "clientCIDR": "0.0.0.0/0", "serverAddress": "10.0.2.15:8443" } ] }

获取 Pod 列表

{ "kind": "PodList", "apiVersion": "v1", "metadata": { "resourceVersion": "33074" }, "items": [ { "metadata": { "name": "kubernetes-bootcamp-2321272333-ix8pt", "generateName": "kubernetes-bootcamp-2321272333-", "namespace": "default", "uid": "ba21457c-6b1d-11e6-85f7-1ef9f1dab92b", "resourceVersion": "33003", "creationTimestamp": "2016-08-25T23:43:30Z", "labels": { "pod-template-hash": "2321272333", "run": "kubernetes-bootcamp" }, ... }

2. `kubectl port-forward` 命令及其含义,如何通过 port-forward 访问应用?

   > Forward one or more local ports to a pod.
   >
   > 转发一个或多个本地端口到 Pod 中。
   >
   > Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted.
   >
   > 使用资源类型/名称(例如 deploy/ mydeployment)来选择容器。 如果省略,资源类型默认为 'pod'。

   ```bash
   # 监听本地 5000 端口,转发至 Pod 的 5000 端口
   kubectl port-forward deployment/mydeployment 5000

   # 监听本地 6000 端口,转发至 Pod 的 5000 端口
   kubectl port-forward deployment/mydeployment 6000:5000

   # 监听本地随机端口,转发至 Pod 的 5000 端口
   kubectl port-forward deployment/mydeployment :5000
  1. 修改 Pod label 使其与 Deployment 不相符,集群有什么变化?

    Deployment 控制器会新起一个 nginx Pod,以达到期望的 Replica。

  2. kubectl run 如何向 Pod 注入环境变量?如何查看是否注入成功?

  3. 如何通过 kubectl rollout 将应用回滚到指定版本?

  4. Pod LivenessProbe 如何使用 exec 进行健康检查?

  5. Pod Lifecycle 如何使用 PostStart Hook?

  6. 创建一个 Secret 并在 Pod 内访问。

    创建 Secret

    使用 Secret

  7. 利用环境变量加载 configmap 的例子。

  8. kubernetes 多区域运行。

    多区域运行

Last updated

Was this helpful?