首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从目录部署映像

从目录部署映像
EN

Stack Overflow用户
提问于 2022-09-02 22:57:59
回答 1查看 71关注 0票数 0

我参考了本教程来创建可部署的映像:

https://medium.com/@javatechie/kubernetes-tutorial-run-deploy-spring-boot-application-in-k8s-cluster-using-yaml-configuration-3b079154d232

我想使用这个舵图来部署目录中的映像:

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment # Kubernetes resource kind we are creating
metadata:
  name: spring-boot-k8s
spec:
  selector:
    matchLabels:
      app: spring-boot-k8s
  replicas: 2 # Number of replicas that will be created for this deployment
  template:
    metadata:
      labels:
        app: spring-boot-k8s
    spec:
      containers:
        - name: spring-boot-k8s
          image: springboot-k8s-example:1.0 
# Image that will be used to containers in the cluster
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080 
# The port that the container is running on in the cluster

如何从目录或从url链接的私有码头注册中心部署坞映像springboot-k8s-example:1.0

EN

回答 1

Stack Overflow用户

发布于 2022-09-03 05:15:09

在这里,您需要创建一个图像提取秘密,以便从您自己的存储库中提取图像。我已经复制了您的问题,并将图像推送到我的女贞码头注册中心,然后成功地提取了图像。

这可以通过使用下面的命令来完成--我假设您使用的是坞女贞注册表:

代码语言:javascript
复制
kubectl create secret docker-registry regcred --docker-server=https://index.docker.io/v1/ --docker-username=<docker-username> --docker-password=<your-password> --docker-email=<docker-email

这将创建一个秘密,现在您需要将其添加到部署清单中,以便它可以通过女贞注册表进行身份验证以获取映像。

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment # Kubernetes resource kind we are creating
metadata:
  name: spring-boot-k8s
spec:
  selector:
    matchLabels:
      app: spring-boot-k8s
  replicas: 2 # Number of replicas that will be created for this deployment
  template:
    metadata:
      labels:
        app: spring-boot-k8s
    spec:
      containers:
        - name: spring-boot-k8s
          image: sidharthpai/springboot-k8s-example:1.0
# Image that will be used to containers in the cluster
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
      imagePullSecrets:
      - name: regcred

有关创建图像提取秘密的更多参考:图像提取秘密

现在,要准备舵图,您需要创建一个具有相关名称的图表,然后在舵图( Deployment.yml & Secret.yml )中配置template.Once,这是您需要配置的values.yml。

Deployment.yml (模板)

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment # Kubernetes resource kind we are creating
metadata:
  name: {{ .Values.name}}
spec:
  selector:
    matchLabels:
      app: {{ .Values.app}}
  replicas: 2 # Number of replicas that will be created for this deployment
  template:
    metadata:
      labels:
        app: {{ .Values.app}}
    spec:
      containers:
        - name: {{ .Values.name}}
          image: {{ .Values.image}}
# Image that will be used to containers in the cluster
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
      imagePullSecrets:
      - name: {{ .Values.secret_name}}

Secret.yml(模板)

代码语言:javascript
复制
apiVersion: v1
data:
  .dockerconfigjson: {{ .Values.docker_config}}
kind: Secret
metadata:
  name: {{ .Values.secret_name}}
type: kubernetes.io/dockerconfigjson

Values.yml

代码语言:javascript
复制
name: spring-boot-k8s
app: spring-boot-k8s
image: sidharthpai/springboot-k8s-example:1.0
secret_name: regcred
docker_config: <docker-config-value>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73588524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档