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](http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm "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文件. ![](https://file.jishuzhan.net/article/1689802704638971905/8726a88a780a4fd19f060bb7af904dd7.png) \[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: \ > > Containers: > > nginx: > > Container ID: > > Image: nginx:1.13 > > Image ID: > > Port: 80/TCP > > State: Waiting > > Reason: ContainerCreating > > Ready: False > > Restart Count: 0 > > Volume Mounts: \ > > Environment Variables: \ > > Conditions: > > Type Status > > Initialized True > > Ready False > > PodScheduled True > > No volumes. > > QoS Class: BestEffort > > Tolerations: \ > > 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 \ 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 \ 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 > > \ > > \ > > \ > > \Welcome to nginx!\ > > \ > > body { > > width: 35em; > > margin: 0 auto; > > font-family: Tahoma, Verdana, Arial, sans-serif; > > } > > \ > > \ > > \ > > \Welcome to nginx!\ > > \If you see this page, the nginx web server is successfully installed and > > working. Further configuration is required.\ > > \For online documentation and support please refer to > > \nginx.org\.\
> > Commercial support is available at > > \
nginx.com\.\
> > \\Thank you for using nginx.\\ > > \
> > \
### ******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 \ k8s-node2 test2 2/2 Running 0 5m 172.16.48.3 k8s-master test3 0/2 ContainerCreating 0 4m \ k8s-node2

相关推荐
蒋星熠37 分钟前
全栈开发:从LAMP到云原生的技术革命
微服务·云原生·职场和发展·架构·系统架构·web·devops
Aspartame~39 分钟前
K8s的相关知识总结
java·容器·kubernetes
plusplus1684 小时前
Kubernetes“城市规划”指南:告别资源拥堵与预算超支,打造高效云原生都市
云原生·容器·kubernetes
qq_312920115 小时前
K8s存储类(StorageClass)设计与Ceph集成实战
ceph·容器·kubernetes
Nazi65 小时前
kubeadm部署k8s集群环境搭建
云原生·容器·kubernetes
Brilliantee4045 小时前
藏在 K8s 幕后的记忆中枢(etcd)
容器·kubernetes·etcd
bing.shao5 小时前
gRPC 选型 etcd 的核心优势分析
数据库·微服务·云原生·golang·etcd
焯集新人7 小时前
K8S高可用集群
云原生·容器·kubernetes
楚禾Noah7 小时前
【通用常识】YAML 中的高阶语法
运维·docker·容器
小白不想白a8 小时前
【Ansible】变量、机密、事实
运维·云原生·ansible