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/

相关推荐
wuxingge8 小时前
k8s1.30.0高可用集群部署
云原生·容器·kubernetes
志凌海纳SmartX9 小时前
趋势洞察|AI 能否带动裸金属 K8s 强势崛起?
云原生·容器·kubernetes
锅总9 小时前
nacos与k8s service健康检查详解
云原生·容器·kubernetes
BUG弄潮儿10 小时前
k8s 集群安装
云原生·容器·kubernetes
Code_Artist10 小时前
Docker镜像加速解决方案:配置HTTP代理,让Docker学会科学上网!
docker·云原生·容器
何遇mirror10 小时前
云原生基础-云计算概览
后端·云原生·云计算
颜淡慕潇12 小时前
【K8S系列】kubectl describe pod显示ImagePullBackOff,如何进一步排查?
后端·云原生·容器·kubernetes
Linux运维日记12 小时前
k8s1.31版本最新版本集群使用容器镜像仓库Harbor
linux·docker·云原生·容器·kubernetes
一名路过的小码农14 小时前
ceph 18.2.4二次开发,docker镜像制作
ceph·docker·容器
AI_小站14 小时前
RAG 示例:使用 langchain、Redis、llama.cpp 构建一个 kubernetes 知识库问答
人工智能·程序人生·langchain·kubernetes·llama·知识库·rag