deployment.YAML
##########################
##不支持tab缩进,空格缩进
##开头缩进2个空格
##字符后缩进1个空格,如冒号、逗号
##"---" 文件开始
##"#"注释
####示例
#####https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
#####deployment.yaml 格式如下#####
---------------------------控制器定义--------------------------
---
apiVersion: apps/v1 ###1版本号
kind: Deployment ###1资源类型
metadata: ###1资源元数据
name: web
spec: ###1资源规格
replicas: 3 ###2副本数
selector: ###2标签选择器 metadata.labels 一致
matchLables:
app: web
---------------------------被控对象--------------------------
template: ###2pod模板
metadata: ###3pod元数据
labels:
app: web
spec: ###3pod规格
containers: ###4容器配置
- name: web
image: nginx
#####service.yaml 格式如下#####
apiVersion: apps/v1 ###1版本号
kind: Service ###1资源类型
metadata: ###1资源元数据
name: web
spec: ###1资源规格
ports:
- port: 80 ###3 Service端口
protocol: TCP
targetPort: 80 ###3 镜像内服务端口;如nginx镜像端口80
selector: ###2标签选择器 与Deployment中标签一致
app: web
type: NodePort ###2 Service 类型
https://kubernetes.io/docs/concepts/services-networking/service/
1)、####kubectl get pods
2)、############deployment.yaml
vi deployment.yaml
#####https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
#############
apiVersion: apps/v1
kind: Deployment
metadata:
name: web2
spec:
replicas: 3
selector:
matchLabels:
app: nginx2
template:nginx
metadata:
labels:
app: nginx2
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
3)、############kubectl apply -f deployment.yaml#####新建、更新
#########另一方式###kubectl create deployment web --image=nginx --replicas=3########新建
#####查看deployment.版本
4)、 端口暴露
###########name、app 与deployment.yaml 一致
###https://kubernetes.io/docs/concepts/services-networking/service/
vi service.yaml
--------------------------------------------------------------------
apiVersion: v1
kind: Service
metadata:
name: web2
spec:
selector:
app: nginx2
ports:
- protocol: TCP
port: 80
targetPort: 80
--------------------------------------------------------------------
############kubectl apply -f service.yaml#####新建、更新
######kubectl get service
######## deployment web 端口暴露另一方式#################
##另一方式######## #kubectl expose deployment web2 --port=80 --target-por80 --type=NodePort
5)、 kubectl get pods
kubectl get pods,service
kubectl get endpoints ##########service关联的pod 负载均衡