microk8s 直接部署Pod

本文介绍 microk8s 直接部署pod 提供服务的配置及说明

k8s 使用 kubectl ;microk8s 使用 mkubectl

首先创建 configMap ,在创建Pod的时候需要使用:

1. 先准备好配置文件 dockerimage-test_config.json

2. 执行以下命令,从主机的/etc/dockerimage/dockerimage-test_config.json 文件中创建configMap dockerimage-test

mkubectl create configmap dockerimage-test --from-file=/etc/dockerimage/dockerimage-test_config.json

创建 pod.yaml 文件,文件内容及注释如下

配置文件及注释
apiVersion: v1                                                        #必选,版本号,例如v1
kind: Pod                                                             #必选,Pod    
metadata:                                                             #必选,元数据
  name: dockerimage-test                                              #必选,Pod名称
  namespace: default                                                  #必选,Pod所属的命名空间,default 可以不填
spec:                                                                 #必选,Pod中容器的详细定义
  nodeName: host                                                      #可选,部署在哪个node上
  containers:                                                         #必选,Pod中容器列表 
    - name: dockerimage-test                                          #必选,容器名称
      image: dockerimage/official                                     #必选,容器的镜像名称
      imagePullPolicy: IfNotPresent                                   #获取镜像的策略:Alawys表示总是下载镜像,IfnotPresent表示优先使用本地镜像,否则下载镜像,Nerver表示仅使用本地镜像
      volumeMounts:                                                   #挂载到容器内部的存储卷配置
      - name: dockerimage-test                                        #引用pod定义的共享存储卷的名称,需用下文的volumes[]部分定义的的卷名
        mountPath: /etc/dockerimage/dockerimage-test_config.json      #存储卷在容器内mount的绝对路径,应少于512字符
        subPath: dockerimage-test_config.json                         #使用subPath将configmap挂载到容器中某个目录的文件中
      command: [ "/usr/bin/dockerimage/dockerimage" ]                 #容器的启动命令列表,如不指定,使用打包时使用的启动命令
      args: ["-config=/etc/dockerimage/dockerimage-test_config.json"] #容器的启动命令参数列表
      ports:                                                          #需要暴露的端口库号列表
      - name: inbounds                                                #端口名称
        containerPort: 28002                                          #容器开发对外的端口
        hostPort: 28002                                               #同步开放主机上的端口(主机是上文nodeName)
        protocol: TCP                                                 #端口协议,支持TCP和UDP,默认TCP
  volumes:                                                            #定义磁盘,给上面volumeMounts挂载
  - name: dockerimage-test                                            #volume的名字
    configMap:                                                        #表示使用configmap挂载
      name: dockerimage-test                                          #configmap挂载的名字

创建 Pod

mkubectl create -f Pod.yaml

测试

检查pod 启动状态

 mkubectl get pods,svc  -n default

检查服务是否可以访问

posted @ 2023-06-08 11:03  独思则滞而不通  阅读(141)  评论(0)    收藏  举报