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. Fluent Python: Slice

    Pyhton中序列类型支持切片功能,比如list: >>> numbers = [1, 2, 3, 4, 5] >>> numbers[1:3] [2, 3] tu ...

  2. ES6的新特性(8)——数组的扩展

    数组的扩展 扩展运算符 含义 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[1, 2, 3]) / ...

  3. 软件工程第七周psp

    1.PSP表格 类别 任务 开始时间 结束时间 中断时间 delta时间 立会 汇报昨天的成绩,分配任务,部署计划 10月27日18:00 10月27日18:36 0 36分钟 准备工作 查阅有关资料 ...

  4. 缓存-MemoryCache Class

    这是使用MemoryCache缓存的一个例子. private void btnGet_Click(object sender, EventArgs e) { ObjectCache cache = ...

  5. Strust2: 工作流程

    以下为Struts2的体系结构图: Struts2框架处理用户请求,大体分为以下几个过程: (1)用户发出一个HttpServletRequest请求 (2)请求经过一系列过滤器,最后达到Filter ...

  6. 删除多余的自编译的内核、mysql连接不了的问题

    1.删除多余的自编译的内核 每次Debian发布内核更新,总是有某些内核选项跟自己的硬件不配套,要自己编译内核.编译多了,多余的内核就占用了多余的硬盘空间.我就试过因为/boot分区满了,而导致编译内 ...

  7. 简述Java中Http/Https请求监听方法

    一.工欲善其事必先利其器 做Web开发的人总免不了与Http/Https请求打交道,很多时候我们都希望能够直观的的看到我们发送的请求参数和服务器返回的响应信息,这个时候就需要借助于某些工具啦.本文将采 ...

  8. 团队作业05——测试与发布(alpha阶段)

    测试 请根据团队项目中软件的需求文档.功能说明.系统设计和测试计划,写出软件的测试过程和测试结果,并回答下述问题. 在测试过程中总共发现了多少Bug?每个类别的Bug分别为多少个? 显示计算结果超过看 ...

  9. 微信小程序 对接口常用

    @import '../expert/expert.wxss';   FZ._get('https://didu2.didu86.com/issun/index.php/Home/goodstype/ ...

  10. wireshark系列之wireshark简介

    前言:为什么要学wireshark?工欲善其事必先利其器,wireshark是一款工具软件,主要作用是抓取数据封包,可以帮助我们更加直观更加具象的学习各种网路协议(http.TLS.TCP.UDP.I ...