> For the complete documentation index, see [llms.txt](https://darren.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://darren.gitbook.io/project/k8s-xi-tong-wan-zheng-bu-shu/zhi-zuo-gitbook-wen-dang-jing-xiang-yun-hang-zai-k8s-shang.md).

# 制作 gitbook 文档镜像，运行在 K8S 上

### 1. 制作 gitbook docker images <a href="#id-1-zhi-zuo-gitbookdockerimages" id="id-1-zhi-zuo-gitbookdockerimages"></a>

编写 dockerfile

* dockerfile

```
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
ADD _book/ /usr/share/nginx/html
EXPOSE 80
```

> \_book 为 gitbook 的静态文件，gitbook serve 或 build 会生成该目录。

* 构建镜像

```
docker build -t book:0.01 .
```

* 运行容器（测试）

```
docker run -p 80:80 book:0.01
```

然后通过 docker tag，将其推送至远程的仓库。（如果要发布到正式环境的话）

### 2. 创建 K8S 资源 <a href="#id-2-chuang-jian-k8s-zi-yuan" id="id-2-chuang-jian-k8s-zi-yuan"></a>

* Deployment

```
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  labels:
    k8s-app: gitbook
    qcloud-app: gitbook
  name: gitbook
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: gitbook
      qcloud-app: gitbook
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        k8s-app: gitbook
        qcloud-app: gitbook
    spec:
      containers:
      - image: <YOUR GITBOOK IMAGES>  # gitbook 镜像地址
        imagePullPolicy: IfNotPresent
        name: gitbook
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        securityContext:
          privileged: false
          procMount: Default
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
```

* Service

```
apiVersion: v1
kind: Service
metadata:
  name: gitbook
spec:
  externalTrafficPolicy: Cluster
  ports:
  - name: tcp-80-80
    nodePort: 30226
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    k8s-app: gitbook
    qcloud-app: gitbook
  sessionAffinity: None
  type: LoadBalancer
```

* Ingress

```
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: query-ip
spec:
  rules:
  - host: dhcp.cn
    http:
      paths:
      - backend:
          serviceName: gitbook
          servicePort: 80
        path: /doc
status:
  loadBalancer:
    ingress:
    - ip: <YOUR LoadBalancer IP>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://darren.gitbook.io/project/k8s-xi-tong-wan-zheng-bu-shu/zhi-zuo-gitbook-wen-dang-jing-xiang-yun-hang-zai-k8s-shang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
