当前位置: 首页 > article >正文

【kubernetes】污点配置、cm、secret练习

1、给node01配置污点,污点策略为不可调度,尝试将deployment管理的pod调度到node01

kubectl taint nodes 192.168.99.131 key=value:NoSchedule
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myjob01
  namespace: default
  labels:
    app: myjob01
spec:
  selector:
    matchLabels:
      app: myjob01
  replicas: 1
  template:
    metadata:
      labels:
        app: myjob01
    spec:
      containers:
      - name: myjob01
        image: httpd
        imagePullPolicy: IfNotPresent
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 100m
            memory: 100Mi
    affinity:
        nodeAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
            - key: kubernetes.io/hostname
                operator: In
                values:
                - 192.168.99.131

      restartPolicy: Always

请添加图片描述

2、调度一个自主式pod到node02上,给node02配置污点策略为不可调度并驱逐

kubectl run my-pod2 --image=nginx --overrides='{"spec":{"nodeName":"192.168.99.132"}}'
kubectl taint nodes 192.168.99.132 key=value:NoExecute

请添加图片描述

3、调度一个deployment构建的pod到node02上,给node02配置污点策略为不可调度并驱逐

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mytest3
  namespace: default
  labels:
    app: mytest3
spec:
  selector:
    matchLabels:
      app: mytest3
  replicas: 1
  template:
    metadata:
      labels:
        app: mytest3
    spec:
      # initContainers:
      # Init containers are exactly like regular containers, except:
      # - Init containers always run to completion.
      # - Each init container must complete successfully before the next one starts.
      containers:
      - name: mytest3
        image: tomcat:8
        imagePullPolicy: IfNotPresent
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 100m
            memory: 100Mi
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: In
                values:
                - 192.168.99.132
      restartPolicy: Always

在这里插入图片描述

4、使用configMap存储一个nginx的conf文件,创建pod引用该configMap中的conf文件


# Define HTTP server block.
server {
    # Define the port that Nginx will listen on.
    listen 81;
    # Define the server name (e.g., domain name).
    server_name localhost;

    # Define the root directory for this server block.
    root /usr/share/nginx/html;
    # Define the default index file.
    index index.html index.htm;
    location / {
        # Serve static files.
        try_files $uri $uri/ =404;
    }
}
kubectl create configmap cm1 --from-file=nginx.conf
apiVersion: v1
kind: Pod
metadata:
  name: mypod-cm-web
  labels:
    run: myapp-cm-web
spec:
  volumes:
  - name: web-cm
    configMap:
      name: cm1
  containers:
  - name: myapp-cm-web
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: web-cm
      mountPath: /etc/nginx/conf.d/

在这里插入图片描述

5、创建一个configMap,以volumes的方式挂载configMap,热更新configMap中的值,测试效果

kubectl create configmap cm2 --from-file=index.html

# https://kubernetes.io/docs/concepts/workloads/pods/
apiVersion: v1
kind: Pod
metadata:
  name: "nginxcm"
  namespace: default
  labels:
    app: "nginxcm"
spec:
  containers:
  - name: nginxcm
    image: "nginx:latest"
    resources:
      limits:
        cpu: 200m
        memory: 500Mi
      requests:
        cpu: 100m
        memory: 200Mi
    ports:
    - containerPort: 80
    volumeMounts:
    - name: nginxindex
      mountPath: /usr/share/nginx/html
  volumes:
  - name: nginxindex
    configMap:
      name: cm2
  restartPolicy: Always

在这里插入图片描述

kubectl edit configmap cm2 

在这里插入图片描述
在这里插入图片描述

6、创建一个docker-registry类型的secret,在下载镜像时使用该secret

 docker login --username=shiinanamida registry.cn-hangzhou.aliyuncs.com    
 docker tag nginx:1.14 registry.cn-hangzhou.aliyuncs.com/shiina_space/shiina:nginx1.14      
 docker push registry.cn-hangzhou.aliyuncs.com/shiina_space/shiina:nginx1.14       
kubectl create secret docker-registry myregistrykey \
    --docker-server=registry.cn-hangzhou.aliyuncs.com \
    --docker-username=shiinanamida \
    --docker-password=*******\
    --docker-email=158*****788@163.com
apiVersion: v1
kind: Pod
metadata:
  name: mypod6
spec:
  containers:
  - name: mycontainer
    image: registry.cn-hangzhou.aliyuncs.com/shiina_space/shiina:nginx1.14
  imagePullSecrets:
  - name: myregistrykey

在这里插入图片描述


http://www.kler.cn/a/291154.html

相关文章:

  • uniapp自定义树型结构数据弹窗,给默认选中的节点,禁用所有子节点
  • 【返璞归真】score检验:似然比的得分检验(Likelihood Ratio Score Test)
  • Mybatis加密解密查询操作(sql前),where要传入加密后的字段时遇到的问题
  • 用Java编写简单的文字游戏
  • java list 和数组互相转换的一些方法
  • 【已解决】启动此实时调试器时未使用必需的安全权限。要调试该进程,必须以管理员身份运行此实时调试器。是否调试该进程?
  • 数学基础 -- 线性代数之共轭转置矩阵
  • 体会循环---冒泡排序
  • 2024.9.4
  • 在js渲染的dom中的事件中传递对象
  • 米家商城主题 html 页面源码分享,可用于网页设计作业
  • 室内导航定位系统在医院的应用与部署
  • Kubernetes学习指南:保姆级实操手册05——配置集群HA负载均衡
  • 智能巡检机器人创新设计的关键技术
  • Xml 映射文件中常见的标签
  • python(进阶2)实现自动化注册和登录
  • 长芯微国产LS0102电平转换器/电平移位器P2P替代TXS0102
  • 支付宝线上小程序打开异常
  • VUE3+FLASK+TYPESCRIPT(实习接触,学习并自主实现)
  • 硬件-电源常识
  • Python作为客户端连接websocket
  • 10.2 TCP IP模型、IP协议、IPv4、子网掩码
  • SpringBoot3 项目部署
  • 【计算机毕业设计】微信小程序的美甲店铺座位预约系统
  • 数据结构(6.4_6)——拓扑排序
  • SDIO驱动开发