开发者学堂课程【Kubernetes 极速入门:K8S 集群核心概念 Controller_使用资源清单文件创建 Deployment 控制器类型应用】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/658/detail/10913
K8S 集群核心概念 Controller_使用资源清单文件创建 Deployment 控制器类型应用
内容介绍:
一、编写用于创建 Deployment 控制器类型应用资源清单
二、验证方法
三、进行访问
一、编写用于创建 Deployment 控制器类型应用资源清单
apiversion: apps/v
1(API 的版本)
kind: Dep1oyment
(控制器类型)
metadata:
(源数据有哪些)
name : nginx-apps
l
abe
l
s:
(此处标签可定义也可不定义)
app: nginx
spec:
replicas: 1
selector :
(标签选择器:使应用与 pod 进行关联)
matchLabe
l
s:
app: nginx
template:
metadata:
l
abe
l
s:
(pod 的标签)
app: nginx
spec:
(pod 包含的容器)
containers:
- name: nginxapp
(容器的名字)
image: nginx:
l
atest
imagePu11Policy: IfNotPresent
ports:
- containerPort: 80
具体操作:
[root@master1 yamldir]# vim 03-create-deployment-nginx-app2. yaml
apiversion : apps/v1
kind: Deployment
metadata:
name : nginx-app2
spec :
replicas: 1
selector:
matchLabels :
app: ngin×
template :
metadata :
labels :
app: nginx
下面开始写Pod 的期望(Pod 应该用什么容器进行运行)
spec :
containers :
- name: nginxapp2-container
image: nginx : latest
imagePulipolicy: IfNotPresent
ports:
- name :" nginxapp2
containerPort: 80
创建应用
[root@master1 yamldir]# kubectl apply -f 03-create-deployment-nginx-app2. yaml
deployment.apps/nginx-app2 created
二、验证方法
1.方法一
[ root@master1 yamldir]# kubectl get deployment.apps
NAME READY UP-TO-DATE AVAIiLABLE AGE
nginx-app1 2/2 2 2 18m
nginx-app2 1/1 1 1 30s
2.方法二
[ root@master1 yamldir]#kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-app1-57c7c9c89d 2 2 2 18m
nginx-app2-5db7f7cf75 1 1 1 44s
3.方法三
[ root@master1 yamldir]#kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx- app1-57c7c9c89d-qp8h8 1/1 Running 0 19m
nginx-app1-57c7c9c89d-tq868 1/1 Running 0 19m
ginx-app2 -5db7f7cf75-vgdl2 1/1 Running 0 70s
三、进行访问
[ root@master1 yamldir]#kubectl get pods -o wide
NAME
READY STATUS RESTARTS AGE IP
NODE NOMINATED NODE READINESS GATES
nginx-app1-57c7c9c89d-qp8h8 1/1 Running 0 19m 172.16.235.130
worker1
nginx-app1-57c7c9c89d-tq868 1/1 Running 0 19m 172.16.189.66
worker2
iginx-app2 -5db7f7cf75-vgdl2 1/ 1 Running 0 87s 172.16.235.131
Worker 1
[ root@master1 yamldir]# curl http :/ /172.16.235.131