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 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/f8b6d887f9b74ec8bc586e6b2d582674.png) 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/

相关推荐
海鸥811 小时前
podman和与docker的比较 及podman使用
docker·容器·podman
GreenMountainEcho7 小时前
Kubernetes 入门篇之 Node 安装与部署
云原生·容器·kubernetes
zyk_5208 小时前
Docker desktop如何汉化
运维·docker·容器
韭菜盖饭8 小时前
解决Docker端口映射后外网无法访问的问题
运维·docker·容器
jingjingjing11119 小时前
笔记:docker安装(ubuntu 20.04)
笔记·docker·容器
ghostwritten9 小时前
Rancher Backup
kubernetes·rancher
qq_3392822310 小时前
docker之network
运维·docker·容器
alden_ygq10 小时前
k8s statefulset pod重启顺序
云原生·容器·kubernetes
ghostwritten10 小时前
k8s黑科技:Linux+Vagrant+VirtualBox开启Kubernetes奇幻之旅
linux·科技·kubernetes
@郭小茶12 小时前
windows部署docker
windows·docker·容器