2024.9.14(RC和RS)

news2024/9/20 14:55:09

一、replicationcontroller (RC)

1、更改镜像站

[root@k8s-master ~]# vim /etc/docker/daemon.json

{
    "registry-mirrors": [
        "https://do.nark.eu.org",
        "https://dc.j8.work",
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
2、加载启动docker服务

[root@k8s-master ~]# systemctl daemon-reload
[root@k8s-master ~]# systemctl start docker

3、拉取常用镜像

[root@k8s-master ~]# docker pull centos
[root@k8s-master ~]# docker pull nginx
[root@k8s-master ~]# docker pull mysql:5.7.44

[root@k8s-master ~]# docker pull haproxy

[root@k8s-master ~]# docker images

REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
haproxy      latest    a782c02b8259   10 days ago    103MB
nginx        latest    39286ab8a5e1   4 weeks ago    188MB
mysql        5.7.44    5107333e08a8   9 months ago   501MB
centos       latest    5d0da3dc9764   2 years ago    231MB
4、使用docker save指令打包镜像

[root@k8s-master ~]# docker save -o centos.tar centos:latest
[root@k8s-master ~]# docker save -o nginx.tar nginx:latest
[root@k8s-master ~]# docker save -o haproxy.tar haproxy:latest
[root@k8s-master ~]# docker save -o mysql.tar mysql:5.7.44

5、使用ctr指令将tar包导入到containerd的镜像中

[root@k8s-master ~]# ctr -n k8s.io images import centos.tar --platform=linux/amd64

[root@k8s-master ~]# ctr -n k8s.io images import nginx.tar --platform=linux/amd64

[root@k8s-master ~]# ctr -n k8s.io images import haproxy.tar --platform=linux/amd64

[root@k8s-master ~]# ctr -n k8s.io images import mysql.tar --platform=linux/amd64

6、查看containerd镜像列表

[root@k8s-master ~]# crictl images

IMAGE                                                                         TAG                 IMAGE ID            SIZE
docker.io/library/centos                                                      latest              5d0da3dc97646       239MB
docker.io/library/haproxy                                                     latest              a782c02b82595       106MB
docker.io/library/mysql                                                       5.7.44              5107333e08a87       520MB
docker.io/library/nginx                                                       latest              39286ab8a5e14       192MB
7、在node1和node2节点上引入tar包

[root@k8s-master ~]# scp /etc/docker/daemon.json root@192.168.8.178:/etc/docker/ 

[root@k8s-master ~]# scp ~/*.tar root@192.168.8.178:~/
[root@k8s-master ~]# scp mysql.tar root@192.168.8.178:~/
[root@k8s-master ~]# scp nginx.tar root@192.168.8.178:~/  
[root@k8s-master ~]# scp haproxy.tar root@192.168.8.178:~/  
[root@k8s-master ~]# scp centos.tar root@192.168.8.178:~/
[root@k8s-master ~]# scp /etc/docker/daemon.json root@192.168.8.168:/etc/docker/

[root@k8s-master ~]# scp ~/*.tar root@192.168.8.168:~/

[root@k8s-master ~]# scp centos.tar root@192.168.8.168:~/ 
[root@k8s-master ~]# scp haproxy.tar root@192.168.8.168:~/   
[root@k8s-master ~]# scp nginx.tar root@192.168.8.168:~/
[root@k8s-master ~]# scp mysql.tar root@192.168.8.168:~/

[root@k8s-node2 ~]# systemctl daemon-reload
[root@k8s-node2 ~]# systemctl start docker

[root@k8s-node1 ~]# systemctl daemon-reload
[root@k8s-node1 ~]# systemctl start docker

[root@k8s-node2 ~]# ctr -n k8s.io images import mysql.tar --platform=linux/amd64  //指定平台
[root@k8s-node2 ~]# ctr -n k8s.io images import nginx.tar --platform=linux/amd64
[root@k8s-node2 ~]# ctr -n k8s.io images import haproxy.tar --platform=linux/amd64
[root@k8s-node2 ~]# ctr -n k8s.io images import centos.tar --platform=linux/amd64
[root@k8s-node1 ~]# ctr -n k8s.io images import haproxy.tar --platform=linux/amd64
[root@k8s-node1 ~]# ctr -n k8s.io images import centos.tar --platform=linux/amd64
[root@k8s-node1 ~]# ctr -n k8s.io images import nginx.tar --platform=linux/amd64
[root@k8s-node1 ~]# ctr -n k8s.io images import mysql.tar --platform=linux/amd64

8、是由kubectl run 创建pod

[root@k8s-master ~]# kubectl run test001 --image docker.io/library/nginx:latest --image-pull-policy=IfNotPresent

[root@k8s-master ~]# kubectl get po

NAME                             READY   STATUS    RESTARTS   AGE
test001                          1/1     Running   0          84s

[root@k8s-master ~]# kubectl describe pod test001
[root@k8s-master ~]# kubectl describe pod test001

Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m26s  default-scheduler  Successfully assigned default/test001 to k8s-node1
  Normal  Pulled     2m25s  kubelet            Container image "docker.io/library/nginx:latest" already present on machine
  Normal  Created    2m25s  kubelet            Created container test001
  Normal  Started    2m25s  kubelet            Started container test001
9、使用配置文件创建pod

[root@k8s-master ~]# vim test0007.yaml

apiVersion: v1
kind: Pod
metadata:
        name: test0007
        labels:
                name: test0007
spec:
        containers:
        -       name: test0007nginx
                image: docker.io/library/nginx:latest
                imagePullPolicy: IfNotPresent
                ports:
                -       name: nginxport
                        containerPort: 80

[root@k8s-master ~]# mv test0007.yaml pods/
[root@k8s-master ~]# cd pods/

[root@k8s-master pods]# kubectl create -f test0007.yaml 

[root@k8s-master pods]# kubectl get po

NAME                             READY   STATUS    RESTARTS   AGE
test0007                         1/1     Running   0          4s
10、添加两个容器

[root@k8s-master pods]# kubectl delete -f test0007.yaml 
[root@k8s-master pods]# vim test0007.yaml

apiVersion: v1
kind: Pod
metadata:
        name: test0007
        labels:
                name: test0007
spec:
        containers:
        -       name: test0007nginx
                image: docker.io/library/nginx:latest
                imagePullPolicy: IfNotPresent
                ports:
                -       name: nginxport
                        containerPort: 80
        -       name: test0007centos
                image: docker.io/library/centos:latest
                imagePullPolicy: Never
                command:
                - sleep
                - infinity

[root@k8s-master pods]# kubectl create -f test0007.yaml 

[root@k8s-master pods]# kubectl get po
NAME                             READY   STATUS    RESTARTS   AGE
test0007                         2/2     Running   0          9s
11、监控容器运行的5个切入点

postStart startup lived ready perStop

12、replicationcontroller (RC)

[root@k8s-master pods]# kubectl delete -f test0007.yaml 

[root@k8s-master pods]# vim test0007.yaml

# 版本
apiVersion: v1
# 类型
kind: Pod
# 数据
metadata:
        name: test0007
        labels:
                name: test0007
#信息
spec:
        # 重启策略
        restartPolicy: OnFailure
        containers:
        -       name: test0007nginx
                image: docker.io/library/nginx:latest
                imagePullPolicy: IfNotPresent
                ports:
                -       name: nginxport
                        containerPort: 80
                startupProbe:
                        tcpSocket:
                                port: 80
                        initialDelaySeconds: 10
                        timeoutSeconds: 2  #超时
                        periodSeconds: 20
                        successThreshold: 1
                        failureThreshold: 2
                readinessProbe:
                       httpGet:
                                port: 80
                                path: /index.html
                        initialDelaySeconds: 10
                        timeoutSeconds: 2
                        periodSeconds: 20
                        successThreshold: 1
                        failureThreshold: 2
                livenessProbe:
                        tcpSocket:
                                port: 80
                        initialDelaySeconds: 10
                        timeoutSeconds: 2
                        periodSeconds: 20
                        successThreshold: 1
                        failureThreshold: 2
        -       name: test0007centos
                image: docker.io/library/centos:latest
                imagePullPolicy: Never
                command:
                - sleep
                - infinity                        

[root@k8s-master pods]# kubectl create -f test0007.yaml 

[root@k8s-master pods]# vim test0007.yaml

 41                 lifecycle:
 42                         postStart:
 43                                 exec:
 44                                         command:
 45                                         - sh
 46                                         - c
 47                                         - mkdir /data
 48                         preStop:
 49                                 exec:
 50                                         command:
 51                                         - sh
 52                                         - c
 53                                         - pkill nginx;sleep     30; 

[root@k8s-master pods]# kubectl delete -f test0007.yaml 

[root@k8s-master pods]# kubectl create -f test0007.yaml 

[root@k8s-master pods]# vim test0008.yaml
 

apiVersion: v1
kind: ReplicationController
metadata:
        name: nginx0
spec:
        replicas: 3
        selector:
                app: nginx0
        # 模板
        template:
                # pod 源数据
                metadata:
                        # pod名称
                        name: ngixn0
                        # pod标签
                        labels:
                                app: nginx
                # pod详细信息
                spec:
                        containers:
                        -       name: nginx0
                                image: docker.io/library/nginx:l
atest
                                imagePullPolicy: Never
                                ports:
                                -       name: containerport
                                        containerPort: 80

[root@k8s-master pods]# kubectl create -f test0008.yaml 
replicationcontroller/nginx0 created
[root@k8s-master pods]# kubectl get po

NAME                             READY   STATUS     RESTARTS      AGE
cluster-test1-54575cf56c-46mb4   1/1     Running    3 (51m ago)   3h59m
nginx0-25xpx                     1/1     Running    0             14s
nginx0-49n2k                     1/1     Running    0             14s
nginx0-6lzvw                     1/1     Running    0             14s

[root@k8s-master pods]# kubectl delete pod nginx0-49n2k   //删除后会自动创建
pod "nginx0-49n2k" deleted
[root@k8s-master pods]# kubectl get po

NAME                             READY   STATUS     RESTARTS      AGE
cluster-test1-54575cf56c-46mb4   1/1     Running    3 (52m ago)   4h
nginx0-25xpx                     1/1     Running    0             103s
nginx0-6lzvw                     1/1     Running    0             103s
nginx0-gf22s                     1/1     Running    0             3s
[root@k8s-master pods]# kubectl get po -owide
NAME                             READY   STATUS    RESTARTS      AGE     IP               NODE        NOMINATED NODE   READINESS GATES
cluster-test1-54575cf56c-46mb4   1/1     Running   3 (54m ago)   4h2m    172.16.36.77     k8s-node1   <none>           <none>
nginx0-25xpx                     1/1     Running   0             3m23s   172.16.36.81     k8s-node1   <none>           <none>
nginx0-6lzvw                     1/1     Running   0             3m23s   172.16.169.141   k8s-node2   <none>           <none>
nginx0-gf22s                     1/1     Running   0             103s    172.16.169.143   k8s-node2   <none>           <none>

[root@k8s-master pods]# curl http://172.16.36.81:80

[root@k8s-master pods]# kubectl top node

NAME         CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k8s-master   159m         7%     1147Mi          66%       
k8s-node1    50m          2%     843Mi           49%       
k8s-node2    58m          2%     897Mi           52%     

[root@k8s-master pods]# kubectl delete -f test0008.yaml    //根据文件完全删除

[root@k8s-master pods]# kubectl delete replicationcontrollers nginx0  //删除

二、replicaSet

[root@k8s-master pods]# vim test0009.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
        name: nginx1
apiVersion: apps/v1
kind: ReplicaSet
metadata:
        name: nginx1
spec:
        replicas: 3
        selector:
                matchLabels:
                         tier: nginx1
                matchExpressions:
                -     key: tier
                      operator: In
                      values: [nginx1]
        template:
                metadata:
                        name: nginx1
                        labels:
                                app: guestbook
                                tier: nginx1
                spec:
                        #restartPolicy: OnFailure
                        containers:
                        -     name: nginx1
                              image: docker.io/library/nginx:latest
                              imagePullPolicy: Never
                              ports:
                              -     name: nginxport
                                    containerPort: 80

[root@k8s-master pods]# kubectl create -f test0009.yaml 

[root@k8s-master pods]# kubectl get po

NAME                             READY   STATUS    RESTARTS      AGE
cluster-test1-54575cf56c-46mb4   1/1     Running   5 (52s ago)   5h9m
nginx1-jg6lp                     1/1     Running   0             35s
nginx1-r5hlp                     1/1     Running   0             35s
nginx1-s26lm                     1/1     Running   0             35s

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2135721.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

windows远程桌面连接ubuntu

通过 Windows 远程连接到 Ubuntu 的桌面环境&#xff0c;可以使用 远程桌面协议&#xff08;RDP&#xff09; 来实现远程登录。 准备工作 一台安装了 Ubuntu 的服务器或计算机。一台 Windows 电脑&#xff08;安装远程桌面客户端&#xff09;。两台机器必须在同一网络中&…

M3U8是什么,如何解析下载

M3U8是什么&#xff1f;如何解析下载 M3U8是苹果公司推出的视频播放标准&#xff0c;准确来说是一种索引文件&#xff0c;使用M3U8文件实际上是通过它来解析对应的放在服务器上的视频网络地址&#xff0c;从而实现在线播放。M3U8文件使用UTF-8字符编码。M3U8是一种常见的流媒体…

基于SpringBoot的甜品店管理系统

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、SSM项目源码 系统展示 【2025最新】基于JavaSpringBootVueMySQL的蛋糕甜品店管理系…

下载docker镜像报错,dial tcp x.x.x.x:443: connect: connection refused

原因是:国外的连接超时了. 解决方案改为阿里云的数据源 打开阿里云 搜索&#xff1a;容器镜像服务 ACR 把你自己的这个直接复制在linux sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-EOF { "registry-mirrors": ["你自己的"] }…

接口发送 xml 格式的数据如何测试?

什么是 xml &#xff1f; xml 是一种和 html 非常类似的语言&#xff0c;采取一定的格式展示数据。比如&#xff1a; 这个例子非常形象的指明&#xff1a; 这是一个便条 便条是给你的 便条是我写的 标题是&#xff1a;提醒 内容是&#xff1a;今晚八点&#xff0c;不见不散…

【docker】docker 关键技术 —— 镜像制作

docker 镜像制作 镜像制作及原因Docker 镜像制作方式快照方式制作镜像制作命令 Dockerfile 制作镜像Dockerfile 是什么Dockerfile 格式为什么需要 Dockerfilegitee 详细使用 Dockerfile 教程 镜像制作及原因 镜像制作是因为某种需求&#xff0c;官方的镜像无法满足需求&#x…

云服务器和物理服务器的区别在哪

在当今数字化的时代&#xff0c;服务器在企业和个人的信息技术架构中扮演着至关重要的角色。其中&#xff0c;云服务器和物理服务器是两种主要的服务器类型&#xff0c;它们在多个方面存在着明显的区别。 一、硬件方面 物理服务器是实实在在的物理硬件设备&#xff0c;它由机…

写论文还在卡壳?教你用ChatGPT轻松搞定过渡段落!

AIPaperGPT&#xff0c;论文写作神器~ https://www.aipapergpt.com/ 在写论文的路上&#xff0c;最让人头疼的除了查重率飙升&#xff0c;估计就是文献综述了吧&#xff01; 想想看&#xff0c;文献一篇接着一篇&#xff0c;脑子都快炸了&#xff0c;还得想办法把它们连接得…

使用JLink V8烧写友善之臂Mini2440 Superboot2440.bin到NORflash里

1 开发环境 PC&#xff1a;Windows 11、开发板Mini2440、仿真器JLink V8、Jlink转接板、JLinkARM烧录工具V4.34版本Setup_JLinkARM_V434.exe 准备工作&#xff1a;安装好烧录工具JLinkARM&#xff0c;按照网上的接线方法将PC、开发板和JLink仿真器连接起来。 组网&#xff1a;…

Radware Alteon 负载均衡-基于URL Filetype的七层负载均衡

作者&#xff1a;Xiaolei Ren Radware Alteon作为一款高性能的负载均衡器&#xff0c;其基于URL Filetype的七层负载均衡功能为众多企业提供了灵活、高效的解决方案。 该案例实现如下需求&#xff1a;当客户端访问服务器时&#xff0c;默认访问10.200.1.100&#xff0c;在ht…

使用Let’s Encrypt 配置 SSL 证书去除浏览器不安全告警

Let’s Encrypt是什么 https://letsencrypt.org/zh-cn/about/如何操作进行配置实现ssl认证 使用 certbot 获取 Let’s Encrypt 的免费 SSL 证书 更新系统软件包 sudo yum update -y安装 EPEL 仓库(Certbot 通常位于 EPEL 仓库中): sudo yum

【C++】STL——vecot的模拟实现

目录 前言总体结构默认成员函数构造函数拷贝构造赋值重载析构函数 vector的相关容量空间以及访问的实现capacity()和size()迭代器实现operator[]reserve vector类对象的修改操作尾插尾删任意位置插入任意位置删除交换和清理 前言 前面我们已经学习了解了vector重要接口的使用&a…

Appium如何简化混合App的测试和自动化

背景&#xff1a;Hybrid App&#xff08;混合模式移动应用&#xff09;是指介于web-app、native-app这两者之间的app&#xff0c;兼具“Native App良好用户交互体验的优势”和“Web App跨平台开发的优势”。 什么是混合型应用&#xff08;Hybrid App&#xff09; 我们可以理解…

iPhone 16预售已开,沙漠金色最抢手,喜提新机后别忘了这件事!

9月13日20点&#xff0c;iPhone 16系列正式开启官方预购。今年全新的iphone16不仅新增相机按钮和AI功能&#xff0c;还增加了沙漠金配色。“加量不加价”的iPhone 16系列开售依旧火爆&#xff0c;iPhone 16系列开售1分钟内&#xff0c;苹果官方网站一度被消费者买到崩&#xff…

EasyExcel 快速入门

目录 一、 EasyExcel简介 官网链接&#xff1a; 代码链接&#xff1a; 二、 EasyExcel快速上手 引入依赖&#xff1a; 设置Excel相关注解 编写对应的监听类&#xff1a; 简单写入数据&#xff1a; 简单读取数据&#xff1a; 不需要使用监听器&#xff1a; 需要使…

U盘一打开就让格式化怎么办?教你快速解决方法

在日常生活和工作中&#xff0c;U盘已成为我们存储和传输数据的重要工具。然而&#xff0c;有时我们会遇到一个令人头疼的问题&#xff1a;当插入U盘后&#xff0c;电脑提示需要格式化才能使用。这时&#xff0c;我们该如何应对呢?本文将为大家详细介绍U盘提示格式化的原因及解…

野生动物检测系统源码分享

野生动物检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer Vis…

时序必读论文06|PITS : 基于非依赖策略学习时序patch特征表示

论文标题&#xff1a;LEARNING TO EMBED TIME SERIES PATCHES INDEPENDENTLY 下载地址&#xff1a;https://arxiv.org/pdf/2312.16427v1.pdf 开源代码&#xff1a;https://github.com/seunghan96/pits 前言 之前的文章我们读了Patch TST&#xff0c;建议大家阅读原论文&…

数据结构修炼——顺序表和链表的OJ题练习

目录 一、顺序表相关OJ题1 移除元素题目解析 2 合并两个有序数组题目解析 二、链表相关OJ题1 移除链表元素题目解析 2 反转链表题目解析 3 链表的中间结点题目解析 4 合并两个有序链表题目解析 5 链表的回文结构题目解析 6 相交链表题目解析 7 环形链表的判断题目解析 8 环形链…

共享单车轨迹数据分析:以厦门市共享单车数据为例(四)

副标题&#xff1a;共享单车与地铁接驳距离探究——以厦门市为例 关于轨道交通站点接驳范围的研究早已屡见不鲜&#xff0c;通常认为以站点为圆心、800米作为地铁站直接的服务范围是合理的。近年来&#xff0c;随着轨道、公交和慢行交通三网融合概念的提出&#xff0c;慢行交通…