In this scenario, you'll learn how to use Kubectl to create and launch Deployments, Replication Controllers and expose them via Services by writing yaml definitions.

YAML definitions define the Kubernetes Objects that become scheduled for deployment. The objects can be updated and redeployed to the cluster to change the configuration.

Step 1 - Create Deployment

One of the most common Kubernetes object is the deployment object. The deployment object defines the container spec required, along with the name and labels used by other parts of Kubernetes to discover and connect to the application.

Copy the following definition to the editor. The definition defines how to launch an application called webapp1 using the Docker Image katacoda/docker-http-serverthat runs on Port 80.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp1
spec:
replicas:
template:
metadata:
labels:
app: webapp1
spec:
containers:
- name: webapp1
image: katacoda/docker-http-server:latest
ports:
- containerPort:

This is deployed to the cluster with the command

kubectl create -f deployment.yaml

As it's a Deployment object, a list of all the deployed objects can be obtained via k

ubectl get deployment

Details of individual deployments can be outputted with

kubectl describe deployment webapp1

Step 2 - Create Service

Kubernetes has powerful networking capabilities that control how applications communicate. These networking configurations can also be controlled via YAML.

Copy the Service definition to the editor. The Service selects all applications with the label webapp1. As multiple replicas, or instances, are deployed, they will be automatically load balanced based on this common label. The Service makes the application available via a NodePort.

apiVersion: v1
kind: Service
metadata:
name: webapp1-svc
labels:
app: webapp1
spec:
type: NodePort
ports:
- port:
nodePort:
selector:
app: webapp1

All Kubernetes objects are deployed in a consistent way using kubectl.

Deploy the Service with

kubectl create -f service.yaml

As before, details of all the Service objects deployed with

kubectl get svc

By describing the object it's possible to discover more details about the configuration

kubectl describe svc webapp1-svc.
curl host01:

Step 3 - Scale Deployment

Details of the YAML can be changed as different configurations are required for deployment. This follows an infrastructure as code mindset. The manifests should be kept under source control and used to ensure that the configuration in production matches the configuration in source control.

Update the deployment.yaml file to increase the number of instances running. For example, the file should look like this:

replicas: 
Updates to existing definitions are applied using kubectl apply. To scale the number of replicas, deploy the updated YAML file using 
kubectl apply -f deployment.yaml

Instantly, the desired state of our cluster has been updated, viewable with 
kubectl get deployment

Additional Pods will be scheduled to match the request. 
kubectl get pods

As all the Pods have the same label selector, they'll be load balanced behind the Service NodePort deployed.

Issuing requests to the port will result in different containers processing the request

curl host01:

Additional Kubernetes Networking details and Object Definitions will will be covered in future scenarios.

Kubernetes - Deploy Containers Using YAML的更多相关文章

  1. Kubernetes - Deploy Guestbook example on Kubernetes

    This scenario explains how to launch a simple, multi-tier web application using Kubernetes and Docke ...

  2. kubernetes之kubectl与YAML详解1

    k8s集群的日志,带有组件的信息,多看日志. kubectl命令汇总 kubectl命令汇总 kubectl命令帮助信息 [root@mcwk8s04 ~]# kubectl -h kubectl c ...

  3. Kubernetes - Start containers using Kubectl

    In this scenario, you'll learn how to use Kubectl to create and launch Deployments, Replication Cont ...

  4. kubernetes 水平伸缩及yaml格式编写

    Replication Controller:用来部署.升级PodReplica Set:下一代的Replication ControllerDeployment:可以更加方便的管理Pod和Repli ...

  5. Kubernetes K8S之通过yaml文件创建Pod与Pod常用字段详解

    YAML语法规范:在kubernetes k8s中如何通过yaml文件创建pod,以及pod常用字段详解 YAML 语法规范 K8S 里所有的资源或者配置都可以用 yaml 或 Json 定义.YAM ...

  6. kubernetes创建资源对象yaml文件例子--pod详解

    apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 metadata: #资源的元数据/属性 name: ...

  7. Kubernetes——YAML文件

    kubernetes——yaml文件的编写yaml文件的结尾后缀名.yaml或者.yml都能够识别.yaml文件就像脚本一样,可以放在任意的位置.编写yaml文件需要用到的帮助手册的查看: kubec ...

  8. [置顶] kubernetes创建资源yaml文件例子--pod

    kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...

  9. kubernetes实战篇之helm示例yaml文件文件详细介绍

    系列目录 前面完整示例里,我们主要讲解helm打包,部署,升级,回退等功能,关于这里面的文件只是简单介绍,这一节我们详细介绍一下这里面的文件,以方便我们参照创建自己的helm chart. Helm ...

随机推荐

  1. Hibernate查询的六种方式

        Hibernate查询的六种方式 分别是HQL查询,对象化查询Criteria方法,动态查询DetachedCriteria,例子查询,sql查询,命名查询. 如果单纯的使用hibernate ...

  2. Coloring a Tree(耐心翻译+思维)

    Description You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the ...

  3. Scrum7

    冲刺阶段的总结 一.各个成员今日完成的任务 组员 任务分工 贡献 林泽宇 团队分工.撰写博客.修改完善需求规格说明书.整理代码规范 李涵 后端架构设计 尹海川 logo设计修改.数据库数据 郏敏杰 课 ...

  4. Spark Shuffle之Sort Shuffle

    源文件放在github,随着理解的深入,不断更新,如有谬误之处,欢迎指正.原文链接https://github.com/jacksu/utils4s/blob/master/spark-knowled ...

  5. Hibernate(五)

    注解高级(原文再续书接上一回) 7.继承映射 第一种:InheritanceType.JOINED 查询时会出现很多join语句. package com.rong.entity.joined; im ...

  6. Struts2(六)

    以下内容是基于导入struts2-2.3.32.jar包来讲的 1.OGNL OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表 ...

  7. spring重定向与转发

    1.重定向 A,通过ModelAndView以及RedirectView @RequestMapping("/login1.do") public ModelAndView log ...

  8. python 将base64字符串还原为图片

    今天弄验证码的时候发现,验证码的图片的src竟然是下面的这么一个一串字符串,吓到,好像不可以http请求的,第一次见,就好尴尬,去网上搜索了一下,说是: 这是Data URI scheme. data ...

  9. JAVA字节流(读写文件)

    InputStream此抽象类是表示字节输入流的所有类的超类.需要定义 InputStream 的子类的应用程序必须始终提供返回下一个输入字节的方法. int available()返回此输入流方法的 ...

  10. Additinal Dependencies和#pragma comment(lib,"*.lib")的分析

     网上.一些书上也写道,这两种方式作用一样.其实仔细分析,它们两者还是有非常大的差异的. Additinal Dependencies和#pragma comment(lib,"*.lib& ...