Kubernetes - Deploy Containers Using YAML
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的更多相关文章
- Kubernetes - Deploy Guestbook example on Kubernetes
		
This scenario explains how to launch a simple, multi-tier web application using Kubernetes and Docke ...
 - kubernetes之kubectl与YAML详解1
		
k8s集群的日志,带有组件的信息,多看日志. kubectl命令汇总 kubectl命令汇总 kubectl命令帮助信息 [root@mcwk8s04 ~]# kubectl -h kubectl c ...
 - Kubernetes - Start containers using Kubectl
		
In this scenario, you'll learn how to use Kubectl to create and launch Deployments, Replication Cont ...
 - kubernetes 水平伸缩及yaml格式编写
		
Replication Controller:用来部署.升级PodReplica Set:下一代的Replication ControllerDeployment:可以更加方便的管理Pod和Repli ...
 - Kubernetes K8S之通过yaml文件创建Pod与Pod常用字段详解
		
YAML语法规范:在kubernetes k8s中如何通过yaml文件创建pod,以及pod常用字段详解 YAML 语法规范 K8S 里所有的资源或者配置都可以用 yaml 或 Json 定义.YAM ...
 - kubernetes创建资源对象yaml文件例子--pod详解
		
apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 metadata: #资源的元数据/属性 name: ...
 - Kubernetes——YAML文件
		
kubernetes——yaml文件的编写yaml文件的结尾后缀名.yaml或者.yml都能够识别.yaml文件就像脚本一样,可以放在任意的位置.编写yaml文件需要用到的帮助手册的查看: kubec ...
 - [置顶]
        kubernetes创建资源yaml文件例子--pod
		
kubernetes创建pod的yaml文件,参数说明 apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 ...
 - kubernetes实战篇之helm示例yaml文件文件详细介绍
		
系列目录 前面完整示例里,我们主要讲解helm打包,部署,升级,回退等功能,关于这里面的文件只是简单介绍,这一节我们详细介绍一下这里面的文件,以方便我们参照创建自己的helm chart. Helm ...
 
随机推荐
- 2018-2019-20172321 《Java软件结构与数据结构》第四周学习总结
			
2018-2019-20172321 <Java软件结构与数据结构>第四周学习总结 教材学习内容总结 第六章 6.1列表集合 列表集合是一种概念性表示法,其思想是使事物以线性列表的方式进行 ...
 - Java:有关自定数组的学习
			
Java:有关==自定数组==的学习 在 ==<Java程序设计与数据结构教程>== 里我在==P212~P213==页看到一个GradeRange的程序,它用的数组是自定设定的Grade ...
 - c# 调用c++dll二次总结
			
1.pinvoke结构不对称,添加语句(网上有) 2.含回调函数,成员参数的结构体必须完全,尽管自己用不到. 3.加深对c++指针的理解.一般情况下,类型加*等效于c++中的ref.但对于short* ...
 - Nginx 使用札记
			
nginx是什么? nginx是俄罗斯人 Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的一个十分轻量级的HTTP服务器.它是一个高性能的HTTP和反向代理服务器,同时也可以作 ...
 - 团队Alpha冲刺(五)
			
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
 - 第二章 script元素
			
<script>元素  async:可选.表示应该立即下载脚本,但不应妨碍页面中的其他操作,比如下载其他资源或等待加载其他脚本.只对外部脚本文件有效.  charset:可选.表示通过 ...
 - QCryptographicHash实现哈希值计算,支持多种算法
			
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QCryptographicHash实现哈希值计算,支持多种算法 本文地址:http: ...
 - selenium  概念及练习 !
			
1.selenium中如何判断元素是否存在? 2.selenium中hidden或者是display = none的元素是否可以定位到? 3.selenium中如何保证操作元素的成功率?也就是说如何保 ...
 - QT学习记录
			
QApplication app(argc,argv); 创建了一个QApplication对象,这个对象用于管理应用程序级别的资源.QApplication的构造函数要求两个参数,分别来自main的 ...
 - php 随机密码和盐 来自wordpress
			
生成随机密码或盐. Generate keys and salts using secure CSPRNG $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJ ...