目录
4)发现最先创建的pod运行在k8s-master节点上,下载镜像速度太慢没法运行
k8s常用资源管理
1、创建一个pod
1)创建yuml文件
[root@k8s-master ~]# mkdir k8s
[root@k8s-master ~]# vim ./k8s/nginx.yaml

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 ~]#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

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

3)查看所有pod创建运行状态
[root@k8s-master ~]# kubectl get pod

4)查看指定pod资源
[root@k8s-master ~]# kubectl get pod nginx

5)查看pod运行的详细信息
[root@k8s-master ~]# kubectl describe pod nginx

[root@k8s-master ~]# kubectl get pod nginx -o wide //显示调度节点

6)验证运行的pod
[root@k8s-master ~]# kubectl get pod nginx -o wide

2、pod管理
1)删除pod
[root@k8s-master ~]# kubectl delete pod nginx
2)查看删除pod无法找到
[root@k8s-master ~]# kubectl get pod nginx -o wide

3)创建pod
[root@k8s-master ~]# kubectl create -f ./k8s/nginx.yaml

4)发现最先创建的pod运行在k8s-master节点上,下载镜像速度太慢没法运行
[root@k8s-master ~]# kubectl get pod nginx -o wide

5)访问pod节点中的服务
[root@k8s-master ~]# curl -I http://172.16.7.3

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

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

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

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

3)查看资源使用情况
[root@k8s-master ~]# kubectl get pod -o wide
