(kubernetes)k8s常用资源管理

目录

k8s常用资源管理

1、创建一个pod

1)创建yuml文件

2)创建容器

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

4)查看指定pod资源

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

6)验证运行的pod

2、pod管理

1)删除pod

2)查看删除pod无法找到

3)创建pod

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

5)访问pod节点中的服务

3、pod操作

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

2)创建资源test2

3)查看资源使用情况


k8s常用资源管理

1、创建一个pod

1)创建yuml文件

root@k8s-master \~\]# mkdir k8s \[root@k8s-master \~\]# vim ./k8s/nginx.yaml ![](https://file.jishuzhan.net/article/1689978202857934850/71ddbf451194485d83cbc38cfa09cd00.png) ### 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") ![](https://file.jishuzhan.net/article/1689978202857934850/27c134a0fc414f36a0c86cab39e58b17.png) \[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 ![](https://file.jishuzhan.net/article/1689978202857934850/97afcc56e7594ca9b5791195751f3ca0.png) 前两个命令会生成/etc/rhsm/ca/redhat-uep.pem文件. ![](https://file.jishuzhan.net/article/1689978202857934850/35015022b4df44cd85b742b68e0fbd95.png) \[root@k8s-master \~\]#docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest ![](https://file.jishuzhan.net/article/1689978202857934850/970f2c6a312b4cc98acb5b7639096f15.png) \[root@k8s-master \~\]# kubectl create -f ./k8s/nginx.yaml ![](https://file.jishuzhan.net/article/1689978202857934850/352df1183e634ff59c58eb72236a72e7.png) ### ****3)查看所有pod创建运行状态**** \[root@k8s-master \~\]# kubectl get pod ![](https://file.jishuzhan.net/article/1689978202857934850/77fb7284fe404f1c9b4458ac8fed5e84.png) ### ****4)查看指定pod资源**** \[root@k8s-master \~\]# kubectl get pod nginx ![](https://file.jishuzhan.net/article/1689978202857934850/e8d182a1fba34990827fedba06c1d3fb.png) ### ****5)查看pod运行的详细信息**** \[root@k8s-master \~\]# kubectl describe pod nginx ![](https://file.jishuzhan.net/article/1689978202857934850/f28928a5d0f84a8882cd0a5bdb5c7ba5.png) \[root@k8s-master \~\]# kubectl get pod nginx -o wide //显示调度节点 ![](https://file.jishuzhan.net/article/1689978202857934850/66b4a82609634d08b54027a3e4294176.png) ### ****6)验证运行的pod**** \[root@k8s-master \~\]# kubectl get pod nginx -o wide ![](https://file.jishuzhan.net/article/1689978202857934850/6613eccebdc94739879ac9c7669c9eeb.png) ## ****2、pod管理**** ### ****1)删除pod**** \[root@k8s-master \~\]# kubectl delete pod nginx ### ****2)查看删除pod无法找到**** \[root@k8s-master \~\]# kubectl get pod nginx -o wide ![](https://file.jishuzhan.net/article/1689978202857934850/565e8447a9b24f4d8d9ef36cd890bef9.png) ### ****3)创建pod**** \[root@k8s-master \~\]# kubectl create -f ./k8s/nginx.yaml ![](https://file.jishuzhan.net/article/1689978202857934850/e58b8bea25114c83b3359594982aa511.png) ### ****4)发现最先创建的pod运行在k8s-master节点上,下载镜像速度太慢没法运行**** \[root@k8s-master \~\]# kubectl get pod nginx -o wide ![](https://file.jishuzhan.net/article/1689978202857934850/02ae0eb30892495abe43087d0613d8ba.png) ### ****5)访问pod节点中的服务**** \[root@k8s-master \~\]# curl -I http://172.16.7.3 ![](https://file.jishuzhan.net/article/1689978202857934850/56a46df61fa54e8097bd30c25e811ece.png) ## ****3、pod操作**** ### ****1)在一个pod中修改配置文件运行多个业务容器,**** ****创建资源test1**** \[root@k8s-master \~\]# vim ./k8s/nginx.yaml 配置如下: apiVersion: v1 kind: Pod metadata: name: test1 labels: app: web spec: containers: - name: nginx01 image: nginx:1.16 ports: - containerPort: 80 - name: busybox image: docker.io/busybox:latest command: ["sleep","3600"] ports: - containerPort: 80 ![](https://file.jishuzhan.net/article/1689978202857934850/49a473448a3b429b92a71a7a749316c4.png) \[root@k8s-master \~\]# kubectl create -f ./k8s/nginx.yaml ![](https://file.jishuzhan.net/article/1689978202857934850/2248511d72de4f54b4146a8e5b395376.png) ### ****2)创建资源test2**** \[root@k8s-master \~\]# vim ./k8s/nginx.yaml 配置如下: apiVersion: v1 kind: Pod metadata: name: test2 labels: app: web spec: containers: - name: nginx01 image: nginx:1.16 ports: - containerPort: 80 - name: busybox image: docker.io/busybox:latest command: ["sleep","3600"] ports: - containerPort: 80 ![](https://file.jishuzhan.net/article/1689978202857934850/7f438ab9766b489fb91ee04962e4f574.png) \[root@k8s-master \~\]# kubectl create -f ./k8s/nginx.yaml ![](https://file.jishuzhan.net/article/1689978202857934850/40a8dcf56e0c42fb9eb7224f218d9350.png) ### ****3)查看资源使用情况**** \[root@k8s-master \~\]# kubectl get pod -o wide ![](https://file.jishuzhan.net/article/1689978202857934850/298eea3f9f494a6598976417dd86640f.png)

相关推荐
wdxylb2 小时前
云原生俱乐部-RH134知识点总结(2)
linux·云原生
deeper_wind3 小时前
k8s-单主机Master集群部署+单个pod部署lnmp论坛服务(小白的“升级打怪”成长之路)
云原生·容器·kubernetes
zhenshanrenhao5 小时前
#买硬盘欲安装k8s记
云原生·容器·kubernetes
bing.shao6 小时前
微服务容错与监控体系设计
微服务·云原生·架构
tb_first7 小时前
k8sday09
linux·云原生·容器·kubernetes
稚辉君.MCA_P8_Java8 小时前
豆包 Java的23种设计模式
java·linux·jvm·设计模式·kubernetes
天上掉下来个程小白9 小时前
Docker-14.项目部署-DockerCompose
运维·docker·微服务·容器
星霜笔记13 小时前
Docker 部署 MariaDB+phpMyAdmin+Nextcloud 完整教程
运维·数据库·docker·容器·mariadb
数据知道15 小时前
容器化部署:用Docker封装机器翻译模型与服务详解
docker·容器·机器翻译
40kuai1 天前
kubernetes中数据存储etcd
容器·kubernetes·etcd