k8s常用资源管理

目录

Pod(容器组):Pod是Kubernetes中最小的部署单元,可以包含一个或多个容器。Pod提供了一种逻辑上的封装,使得容器可以一起共享网络和存储资源

1、创建一个pod

2、pod管理

pod操作


Pod(容器组):Pod是Kubernetes中最小的部署单元,可以包含一个或多个容器。Pod提供了一种逻辑上的封装,使得容器可以一起共享网络和存储资源

1、创建一个pod

1)创建yuml文件

root@k8s-master \~# mkdir k8s

root@k8s-master \~# vim ./k8s/nginx.yaml

piVersion: v1

kind: Pod

metadata:

name: nginx

labels:

app: web

spec:

containers:

  • name: nginx

image: nginx:1.13

ports:

  • containerPort: 80

2)创建容器

方法一. yum安装

root@k8s-master \~#yum install *rhsm*

方法二

执行命令:

root@k8s-master \~#wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
root@k8s-master \~# yum -y install *rhsm*

root@k8s-master \~# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm

root@k8s-master \~# rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem

前两个命令会生成/etc/rhsm/ca/redhat-uep.pem文件.

root@k8s-master \~# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest

Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...

latest: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure

26e5ed6899db: Downloading 34.95 MB/74.87 MB

66dbe984a319: Download complete

9138e7863e08: Download complete

创建pod

root@k8s-master \~# kubectl create -f ./k8s/nginx.yaml

pod "nginx" created

3)查看所有pod创建运行状态

root@k8s-master \~# kubectl get pod

NAME READY STATUS RESTARTS AGE

nginx 0/1 ContainerCreating 0 17s

4)查看指定pod资源

root@k8s-master \~# kubectl get pod nginx

NAME READY STATUS RESTARTS AGE

nginx 0/1 ContainerCreating 0 41s

5)查看pod运行的详细信息

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

Name: nginx

Namespace: default

Node: k8s-node2/192.168.50.51

Start Time: Thu, 10 Aug 2023 20:33:09 +0800

Labels: app=web

Status: Pending

IP:

Controllers: <none>

Containers:

nginx:

Container ID:

Image: nginx:1.13

Image ID:

Port: 80/TCP

State: Waiting

Reason: ContainerCreating

Ready: False

Restart Count: 0

Volume Mounts: <none>

Environment Variables: <none>

Conditions:

Type Status

Initialized True

Ready False

PodScheduled True

No volumes.

QoS Class: BestEffort

Tolerations: <none>

Events:

FirstSeen LastSeen Count From SubObjectPath Type ReasonMessage


1m 1m 1 {default-scheduler } Normal Scheduled Successfully assigned nginx to k8s-node2

25s 25s 1 {kubelet k8s-node2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""

1m 4s 3 {kubelet k8s-node2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"

显示调度节点 验证运行的pod

root@k8s-master \~# kubectl get pod nginx -o wide

NAME READY STATUS RESTARTS AGE IP NODE

nginx 0/1 ContainerCreating 0 2m <none> k8s-node2

2、pod管理

1)删除pod

root@k8s-master \~# kubectl delete pod nginx

pod "nginx" deleted

2)查看删除pod无法找到

root@k8s-master \~# kubectl get pod nginx -o wide

Error from server (NotFound): pods "nginx" not found

3)创建pod

root@k8s-master \~# kubectl create -f ./k8s/nginx.yaml

pod "nginx" created

4)发现最先创建的pod运行在k8s-master节点上,下载镜像速度太慢没法运行

root@k8s-master \~# kubectl get pod nginx -o wide

NAME READY STATUS RESTARTS AGE IP NODE

nginx 0/1 ContainerCreating 0 38s <none> k8s-master

5)访问pod节点中的服务

root@k8s-master \~# kubectl get pod nginx -o wide

NAME READY STATUS RESTARTS AGE IP NODE

nginx 1/1 Running 0 21m 172.16.48.2 k8s-master

root@k8s-master \~# curl -l http://172.16.48.2

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

body {

width: 35em;

margin: 0 auto;

font-family: Tahoma, Verdana, Arial, sans-serif;

}

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>

<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>

</body>

</html>

pod操作

1)在一个pod中修改配置文件运行多个业务容器

root@k8s-master \~# vim ./k8s/nginx.yaml

apiVersion: v1

kind: Pod

metadata:

name: test3

labels:

app: web

spec:

containers:

  • name: nginx02

image: nginx:1.13

ports:

  • containerPort: 80

  • name: busybox

image: docker.io/busybox:latest

command: "sleep","3600"

ports:

  • containerPort: 80

~

2)创建资源

root@k8s-master \~# kubectl create -f ./k8s/nginx.yaml

3)查看资源使用情况 Pod会 分配了各自的 IP 过程会有点慢正常现象

root@k8s-master \~# kubectl get pod -o wide

NAME READY STATUS RESTARTS AGE IP NODE

nginx 1/1 Running 0 25m 172.16.48.2 k8s-master

test1 0/2 ContainerCreating 0 9m <none> k8s-node2

test2 2/2 Running 0 5m 172.16.48.3 k8s-master

test3 0/2 ContainerCreating 0 4m <none> k8s-node2

相关推荐
张忠琳15 分钟前
【client-go v0.36.1】WorkQueue 深度分析(上篇)— 模块定位、结构、基础队列与延迟队列
云原生·kubernetes·informer·workqueue·client-go
jieyucx21 分钟前
站在云原生高并发天花板:拆解 Go 语言 GMP 模型与 I/O 多路复用的神级配合
开发语言·云原生·golang
一池秋_38 分钟前
chroot-debian一键部署
android·容器·debian
张忠琳39 分钟前
【client-go v0.36.1】tools/cache 深度分析(上篇)— 模块定位、整体结构、接口与依赖关系
云原生·kubernetes·cache·informer·client-go
张忠琳1 小时前
【client-go v0.36.1】(Reflector Part 1)Reflector 超深度分析 — 模块定位、整体结构、接口与依赖
云原生·kubernetes·informer·client-go·reflector
Demon1_Coder1 小时前
Day4-微服务-Seata
微服务·云原生·架构
张忠琳2 小时前
【client-go v0.36.1】client-go v0.36.1 系统级架构分析(下篇)
云原生·kubernetes·client-go
杨了个杨89822 小时前
Docker简介及安装
运维·docker·容器
IT策士2 小时前
第50篇 k8s之系列总结 + 项目演示与后续扩展
云原生·容器·kubernetes
卧室小白2 小时前
K8S-Pod的生命周期与调度
云原生·容器·kubernetes