k8s笔记0

本文记录了将OpenAPI服务部署到K8s集群的步骤,包括创建命名空间、配置ConfigMap、部署Pod及设置服务进行外部访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

把openapi服务部署上k8s,写了两个yaml文件,一个openapi.conf文件
# 创建命名空间

kubectl create namespace openapi

# 根据config文件创建configmap

kubectl -n openapi create configmap openapi-configmap --from-file=openapi.conf

# 根据deployment.yaml创建pod

kubectl -n openapi create -f deployment_openapi.yaml

# 根据service.yaml创建服务(感觉service就是做了pod外面的转发功能)

kubectl -n openapi create -f service_openapi.yaml

# 获取pod并进入

kubectl -n keystone get pods
kubectl -n keystone exec -it POD-ID -- bash
# service.yaml
apiVersion: v1
kind: Service
metadata:
  name: service-openapi
  namespace: openapi
spec:
  type: NodePort
  ports:
  - name: port-1
    port: 8000 # inner
    targetPort: 8000 # container port
    nodePort: 8000 # out
  selector:
    app: label-openapi
# deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deployment-openapi
  namespace: openapi
spec:
  replicas: 1 # pod number
  template:
    metadata:
      labels:
        app: label-openapi # pod label
    spec:
      containers:
        - name: container-openapi
          image: qiyun/openapi:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 8000
            - containerPort: 22
          volumeMounts:
            - name: openapi # volume name in k8s
              mountPath: /configfile # config file path
      volumes:
        - name: openapi
          configMap:
            name: openapi-configmap # configmap name in k8s
            items:
            - key: openapi.conf # config file name in k8s
              path: openapi.conf # config file path
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值