k8s(Kubernetes)设置 pod,Deployment 域名自定义映射ip,hosts 解析 HostAliases

核心

      hostAliases:
      # 解决服务器内,因路由器配置不全, 不能访问外网问题
        - hostnames:
            - graph.requarks.io
          ip: 104.26.14.122

案例 wiki k8s Deployment

直接 编辑修改 Deployment

kubectl edit Deployment wiki

最后内容如下,如需保存 按 esc 键,最后输入 :wq 保存退出,容器会自动重新生成新的

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: wiki
  name: wiki
spec:
  replicas: 1
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: wiki
  template:
    metadata:
      labels:
        app: wiki
    spec:
      hostAliases:
      # 解决服务器内,因路由器配置不全, 不能访问外网问题
        - hostnames:
            - graph.requarks.io
          ip: 104.26.14.122
      containers:
        - env:
            - name: TZ
              value: Asia/Shanghai
            - name: DB_USER
              value: fox
            - name: DB_PASS
              value: password
            - name: DB_NAME
              value: wiki
            - name: DB_HOST
              value: postgres
            - name: DB_TYPE
              value: postgres
            - name: DB_PORT
              value: "5432"
          image: 'ghcr.io/requarks/wiki:2'
          name: wiki
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
              protocol: TCP
#          resources:
#            limits:
#              memory: 2Gi
#            requests:
#              memory: 2Gi
          volumeMounts:
            - name: vm-data
              mountPath: /wiki/data
            - name: vm-content
              mountPath: /wiki/content
            - name: vm-definition
              mountPath: /wiki/server/modules/search/postgres/definition.yml

      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
        - name: vm-data
          hostPath:
            # 宿主机目录
            path: /www/websites/wiki/data
            # hostPath 卷指定 type,如果目录不存在则创建(可创建多层目录)
            type: DirectoryOrCreate
        - name: vm-content
          hostPath:
            # 宿主机目录
            path: /www/websites/wiki/content
            # hostPath 卷指定 type,如果目录不存在则创建(可创建多层目录)
            type: DirectoryOrCreate
        - name: vm-definition
          hostPath:
            path: /www/websites/wiki/search/definition.yml
            type: FileOrCreate

你可能感兴趣的:(kubernetes,tcp/ip,容器,Deployment)