制作 gitbook 文档镜像,运行在 K8S 上
1. 制作 gitbook docker images
编写 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 资源
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>
Last updated