k8s的基础

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

2.加载启动docker服务

root@k8s-master \~# systemctl daemon-reload

root@k8s-master \~# systemctl start docker

3.拉取常用的镜像

docker pull ...

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 mysql.tar mysql:5.7.44

root@k8s-master \~# docker save -o haproxy.tar haproxy:latest

root@k8s-master \~# docker save -o nginx.tar nginx:latest

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.在node01和node02节点上引入tar包,并使用ctr指令将tar包导入到containerd的镜像中

scp ~/*.tar root@192.168.118.77:~

root@k8s-master \~# scp haproxy.tar root@192.168.118.77:~

root@k8s-node02 \~# 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

cluster-test5-6597c95b6c-28tkj 1/1 Running 10 42h

test001 1/1 Running 0 14s

root@k8s-master \~# kubectl describe pod test001

Normal Pulled 3m29s kubelet Container image "docker.io/library/nginx:latest" already present on machine

9.使用配置文件创建pod

--创建一个容器

复制代码
[root@k8s-master pods]# vim test0007.yaml 
[root@k8s-master pods]# kubectl create -f test0007.yaml 
pod/test0007 created
[root@k8s-master pods]# cat 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 pods]# kubectl get po
NAME                             READY   STATUS    RESTARTS   AGE
cluster-test5-6597c95b6c-28tkj   1/1     Running   10         42h
test0007                         1/1     Running   0          109s
test001                          1/1     Running   0          16m
#删除test0007

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

--创建两个容器

复制代码
[root@k8s-master pods]# cat  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 get po
NAME                             READY   STATUS    RESTARTS   AGE
cluster-test5-6597c95b6c-28tkj   1/1     Running   10         43h
test0007                         2/2     Running   0          5s
test001                          1/1     Running   0          35m

10.监控容器运行的5个切入点

--postStart

--startup

--lived

--ready

--perStop

相关推荐
Z21-X2 小时前
云原生运维学习笔记:Kubernetes Service 发现、类型与 kube-proxy 实战
运维·笔记·学习·云原生·kubernetes
xbzb2 天前
Kubernetes ReplicaSet:副本数自愈、标签接管与 orphan 删除实测
容器·kubernetes·删除·pod·replicaset·orphan
赤生云电竞3 天前
算力调度系统架构实践:计费、配额与抢占策略设计——基于Kubernetes 1.28与YARN 3.3的参数选型
贪心算法·系统架构·kubernetes
如夏倾城4 天前
入侵检测系统(IDS)原理、部署模式与 IPS/防火墙对比
大数据·网络·人工智能·网络安全·云原生·架构·kubernetes
Z21-X4 天前
云原生运维学习笔记:Kubernetes Volume 与 Secret 实验
运维·笔记·学习·云原生·kubernetes
A-刘晨阳6 天前
K8S 二进制集群搭建(一主两从)v1.37.2 版本
运维·云原生·容器·kubernetes·calico·nerdctl
goyeer6 天前
【Kubernetes】Kubernetes之CRI详解
java·容器·kubernetes
wz97546 天前
Kubernetes Pod 深度详解:K8s 最小调度单元
云原生·容器·kubernetes
xbzb7 天前
Kubernetes 节点删除后还有残留?drain、reset 与集群销毁重建全流程
容器·kubernetes·kubectl·集群·reset·drain
正在走向自律7 天前
Infra 现代研发基础设施实战:从 IaC、K8s 到平台工程与可观测性
云原生·容器·kubernetes·terraform·github actions·infra