文章目录
1. 资源管理方式
命令式对象管理:直接使用命令去操作kubernetes资源
kubectl run nginx-pod --image=nginx:1.17.1 --port=80
命令式对象配置:通过命令配置和配置文件去操作kubernetes资源
kubectl create/patch -f nginx-pod.yaml
声明式对象配置:通过apply命令和配置文件去操作kubernetes资源
kubectl apply -f test1.yaml
类型 | 操作对象 | 适用环境 | 优点 | 缺点 |
---|---|---|---|---|
命令式对象管理 | 对象 | 测试 | 简单 | 只能操作活动对象,无法审计、跟踪 |
命令式对象配置 | 文件 | 开发 | 可以审计、跟踪 | 项目大时,配置文件多,操作麻烦 |
声明式对象配置 | 目录 | 开发 | 支持目录操作 | 意外情况下难以调试 |
1.1 命令式对象管理
[root@master ~]# kubectl get pod
/./查看某个pod
[root@master ~]# kubectl get pod POD_NAME
1.2 命令式对象配置
- 创建一个test1.yaml
[root@master ~]# vi test1.yml
apiVersion: v1
kind: Namespace
metadata:
name: dev
---
apiVersion: v1
kind: Pod
metadata:
name: test1
namespace: dev
spec:
containers:
- name: nginx-containers
image: nginx:latest
//执行create命令,创建资源
[root@master ~]# kubectl create -f test1.yml
namespace/dev created
pod/test1 created
- get命令,查看资源
[root@master ~]# kubectl get ns
NAME STATUS AGE
default Active 22h
dev Active 61s
kube-flannel Active 22h
kube-node-lease Active 22h
kube-public Active 22h
kube-system Active 22h
[root@master ~]# kubectl get ns default
NAME STATUS AGE
default Active 22h
- 获取kube-system下的pod列表,查看系统名称空间 <