繁体   English   中英

使用yaml文件将Docker容器部署到Kubernetes

[英]Deploy Docker container to Kubernetes using yaml file

我正在尝试使用YAML文件(本地系统)将Docker容器部署到Kubernetes。

第1部分:Docker容器(工作正常)

  • 我能够运行容器并推入Docker Hub
  • 能够通过浏览器访问容器应用程序。

第2部分:Kubernetes(无效)

  • 编写了包含部署和服务的deployment.yaml文件
  • 部署:成功创建Pod
  • 服务:已添加服务,并尝试通过浏览器访问应用程序,但无法正常工作

    错误:无法访问网站

泊坞窗:

  • 容器被推入Docker Hub
    • 名称:$ ID / tomcat-jenkins
    • 版本:3

Kubernetes:

  • deployment.yaml
    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    metadata:
      name: jenkins
    spec:
      selector:
        matchLabels:
          app: tomcat
      replicas: 2 # tells deployment to run 2 pods matching the template
      template:
        metadata:
          labels:
            app: tomcat
        spec:
          containers:
          - name: tomcat-jenkins
            image: $DOCKER-ID/tomcat-jenkins:3
            ports:
            - containerPort: 80
    # Service
    apiVersion: v1
    kind: Service
    metadata:
      name: jenkins
    spec:
      selector:
        app: tomcat
      ports:
      - protocol: TCP
        port: 80
        targetPort: 80
        nodePort: 31011
      type: NodePort

在Kubenetes容器中部署容器后,我无法访问应用程序。

我不确定我的deployment.yaml文件是否包含某些语法错误。

NodePort上公开服务时,可以使用http:// NodeIP:NodePort`访问它。 对于以上服务,nodeport的值为31011。

这是一个详细的教程 ,解释了在k8s上公开该服务。

ClusterIP(默认)-在群集的内部IP上公开服务。 这种类型使得只能从群集内访问服务。

NodePort-使用NAT在群集中每个选定节点的相同端口上公开服务。 使用:使服务可从群集外部访问。 ClusterIP的超集。

LoadBalancer-在当前云中创建一个外部负载平衡器(如果支持),并为该服务分配一个固定的外部IP。 NodePort的超集

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM