分类 kubernetes 下的文章


sudo docker run \
  --volume=/:/rootfs:ro \
  --volume=/var/run:/var/run:ro \
  --volume=/sys:/sys:ro \
  --volume=/var/lib/docker/:/var/lib/docker:ro \
  --volume=/dev/disk/:/dev/disk:ro \
  --publish=8080:8080 \
  --detach=true \
  --name=cadvisor \
  --privileged \
  --device=/dev/kmsg \
  gcr.io/cadvisor/cadvisor:$VERSION

DEMO

https://game.ipip.icu


Docker

安装Docker

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-19.03.5
systemctl enable docker && systemctl start docker

部署dosgame

docker run -d --name dosgame -p 262:262 oldiy/dosgame-web-docker:latest

高级启动(可选)

需要先将容器内/app/static/games拷贝出来
docker run -d --name dosgame -p 262:262 -v <host/file>:/app/static/games oldiy/dosgame-web-docker:latest

Kubernetes

---
# Source: dosgame/templates/volume-claim.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: caddy-data-pvc
spec:
  storageClassName: nfs-storage
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 3Gi
---
# Source: dosgame/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: dosgame
spec:
  type: NodePort
  ports:
    - port: 262
      nodePort: 26222
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: dosgame
    app.kubernetes.io/instance: dosgame
---
# Source: dosgame/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dosgame
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: dosgame
      app.kubernetes.io/instance: dosgame
  template:
    metadata:
      labels:
        app.kubernetes.io/name: dosgame
        app.kubernetes.io/instance: dosgame
    spec:
      volumes:
        - name: dosgame-data
          persistentVolumeClaim:
            claimName: dosgame-data-pvc
      securityContext:
        { }
      containers:
        - name: dosgame
          securityContext:
            { }
          image: "oldiy/dosgame-web-docker:latest"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 262
              protocol: TCP
          volumeMounts:
            - name: dosgame-data
              mountPath: /app
          resources:
            limits:
              cpu: 1000m
              memory: 1024Mi
            requests:
              cpu: 100m
              memory: 128Mi

简介

excalidraw是一个在线画布工具,可以在网页上随意涂画,多种编辑功能可选,还可以导入图片,保存等功能


项目地址

https://github.com/excalidraw/excalidraw


本站Demo(自用)

https://canvas.ipip.icu


部署

Docker部署

镜像仓库地址: https://hub.docker.com/r/excalidraw/excalidraw

基础环境:

  • Linux
  • Docker

命令:

docker run --rm -dit --name excalidraw -p 5000:80 excalidraw/excalidraw:latest
#请替换5000为你所在主机要暴露该服务web页面的端口

Kubernetes部署

  • 1

    vim excalideaw-deployment.yaml
  • 2

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: excalidraw
    labels:
      app: excalidraw
    spec:
    replicas: 2
    template:
      metadata:
        name: excalidraw
        labels:
          app: excalidraw
      spec:
        containers:
          - name: excalidraw
            image: excalidraw/excalidraw
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                cpu: 500m
                memory: 500Mi
              requests:
                cpu: 10m
                memory: 100Mi
            ports:
              - containerPort: 80
                name: excalidraw
        restartPolicy: Always
    selector:
      matchLabels:
        app: excalidraw

apiVersion: v1
kind: Service
metadata:
name: excalidraw
spec:
type: NodePort
selector:

app: excalidraw

ports:

- port: 80
  nodePort: 12345

***需要修改nodePort端口为你自己的,如果你用其他方式暴露则忽略***

- 3

kubectl create ns excalidraw

创建excalidraw namespace

- 4

kubectl apply -f excalideaw-deployment.yaml -n excalidraw

部署excalidraw 工作负载

如你所见,本站运行在Kubernetes集群中,当某个节点有问题或者需要重启时,依然能提供正常的访问能力,并且可以自动恢复,直接进行维护即可,得益于Kubernetes的调度,让本站的容灾能力得到提升,下面是yaml文件


需要修改的地方

  • storageClassName ##修改为你自己的存储类名
  • storage #持久化存储空间的大小
  • nodePort #暴露在宿主机上的端口

部署

kubectl create ns typecho #创建namespace命名空间
kubectl apply -f typecho.yaml -n typecho

Typecho yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: typecho
  labels:
    app: typecho
spec:
  replicas: 2
  template:
    metadata:
      name: typecho
      labels:
        app: typecho
    spec:
      containers:
        - name: typecho
          image: 80x86/typecho:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              protocol: TCP
              name: http
          env:
            - name: TIMEZONE
              value: "Asia/Shanghai"
          resources:
            requests:
              cpu: "300m"
              memory: "512Mi"
            limits:
              cpu: "1000m"
              memory: "2048Mi"
          volumeMounts:
            - name: typecho-data
              mountPath: /data
              readOnly: false
      volumes:
        - name: typecho-data
          persistentVolumeClaim:
            claimName: typecho-data
      restartPolicy: Always
  selector:
    matchLabels:
      app: typecho
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: typecho-data
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: "nfs-storage2"   #你自己的sc
  resources:
    requests:
      storage: 10Gi    #存储大小
---
---
apiVersion: v1
kind: Service
metadata:
  name: typecho
spec:
  type: NodePort
  selector:
    app: typecho
  ports:
    - port: 80
      nodePort: 12345