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 ...
随机推荐
- A Bug's Life(加权并查集)
Description Background Professor Hopper is researching the sexual behavior of a rare species of bug ...
- HDU 5167 Fibonacci 筛法+乱搞
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: 给你一个x,判断x能不能由斐波那契数列中的数相乘得到(一个数可以重复使用) ...
- HDU 1754 I Hate It 线段树(单点更新,成段查询)
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=1754 题解: 单点更新,成段查询. 代码: #include<iostream> ...
- 蜗牛慢慢爬 LeetCode 2. Add Two Numbers [Difficulty: Medium]
题目 You are given two non-empty linked lists representing two non-negative integers. The digits are s ...
- 更改HTTP头信息
http信息分三部分 1.请求行 GET lizi.php HTTP/1.1 2.HTTP头信 Host: localhost Connection: keep-alive Cache-Contr ...
- 面试- 阿里-. 大数据题目- 给定a、b两个文件,各存放50亿个url,每个url各占64字节,内存限制是4G,让你找出a、b文件共同的url?
假如每个url大小为10bytes,那么可以估计每个文件的大小为50G×64=320G,远远大于内存限制的4G,所以不可能将其完全加载到内存中处理,可以采用分治的思想来解决. Step1:遍历文件a, ...
- css 层加透明度后文字依然清晰
background: rgba(, , , !important; /*实现FF背景透明,文字不透明*/ filter: Alpha(opacity=); background: #0a0a0a; ...
- 【.Net+数据库】Unable to convert MySQL date/time value to System.DateTime
C#读取MySql时,如果存在字段类型为date/datetime时的可能会出现以下问题“Unable to convert MySQL date/time value to System.DateT ...
- 【Python】Python发展历史
起源 Python的作者,Guido von Rossum,荷兰人.1982年,Guido从阿姆斯特丹大学获得了数学和计算机硕士学位.然而,尽管他算得上是一位数学家,但他更加享受计算机带来的乐趣.用他 ...
- js 变量定义的注意点