k8s-deployment控制器

k8s-deployment控制器

1、yaml文件标签学习-指定pod在哪台节点上创建

强制指定pod在指定节点上创建:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web1
  template:
    metadata:
      labels:
        app: web1
    spec:
      nodeName: node01.local # 强制指定pod在node01.local节点上创建
      containers:
      - name: my-pod-dep
        image: 192.168.84.11/k8s/music:v3
        ports:
        - protocol: TCP
          containerPort: 80

给node节点打标签,选择pod在那个标签的node节点运行

查看节点标签

[root@master ~]# kubectl get nodes node01.local --show-labels
NAME           STATUS   ROLES    AGE   VERSION   LABELS
node01.local   Ready    <none>   17h   v1.17.6   
beta.kubernetes.io/arch=amd64,
beta.kubernetes.io/os=linux,
kubernetes.io/arch=amd64,
kubernetes.io/hostname=node01.local,
kubernetes.io/os=linux

打标签

[root@master ~]# kubectl label nodes node01.local disktype=ssd        #打标签
node/node01.local labeled
[root@master ~]# kubectl get nodes node01.local --show-labels
NAME           STATUS   ROLES    AGE   VERSION   LABELS
node01.local   Ready    <none>   17h   v1.17.6   beta.kubernetes.io/arch=amd64,
beta.kubernetes.io/os=linux,
disktype=ssd,                                 #打的标签
kubernetes.io/arch=amd64,
kubernetes.io/hostname=node01.local,
kubernetes.io/os=linux

使用标签

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  selector:
    matchLabels:        #选择下面的template的pod
      app: web1     #选择下面的template的pod
  template:
    metadata:
      labels:
        app: web1
    spec:
      #nodeName: node01.local
      nodeSelector:																		# 选择标签disktype=ssd的节点
        disktype: ssd
      containers:
      - name: my-pod-dep
        image: 192.168.84.11/k8s/music:v3
        ports:
        - protocol: TCP
          containerPort: 80

2、集群扩容方法

replicas:使用replicas标签

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 6                       # 使用replicas标签
  selector:
    matchLabels:    
      app: web1    
  template:
    metadata:
      labels:
        app: web1
    spec:
      #nodeName: node01.local
      nodeSelector:
        disktype: ssd
      containers:
      - name: my-pod-dep
        image: 192.168.84.11/k8s/music:v3
        ports:
        - protocol: TCP
          containerPort: 80

使用命令

[root@master ~]# kubectl edit deployments.apps my-deployment

deployment.apps/my-deployment edited

2、

[root@master ~]# kubectl scale deployment my-deployment --replicas=2

deployment.apps/my-deployment scaled

3、节点调度策略

https://kubernetes.io/zh-cn/docs/concepts/scheduling-eviction/assign-pod-node/

相关推荐
苏苏大大8 分钟前
zookeeper
java·分布式·zookeeper·云原生
一个假的前端男2 小时前
Windows Docker Desktop安装及使用 Docker 运行 MySQL
windows·docker·容器
Linux运维老纪2 小时前
分布式存储的技术选型之HDFS、Ceph、MinIO对比
大数据·分布式·ceph·hdfs·云原生·云计算·运维开发
小马爱打代码2 小时前
125个Docker的常用命令
运维·docker·容器
xiao-xiang2 小时前
jenkins-k8s pod方式动态生成slave节点
java·kubernetes·jenkins
胡八一2 小时前
解决docker: ‘buildx‘ is not a docker command.
运维·docker·容器
QQ_7781329745 小时前
在K8S中使用Values文件定制不同环境下的应用配置详解
kubernetes
m0_748245525 小时前
冯诺依曼架构和哈佛架构的主要区别?
微服务·云原生·架构
huosenbulusi13 小时前
helm推送到harbor私有库--http: server gave HTTP response to HTTPS client
云原生·容器·k8s
不会飞的小龙人14 小时前
Docker Compose创建镜像服务
linux·运维·docker·容器·镜像