目录
K8S模拟项目
Kubectl是管理k8s集群的命令行工具,通过生成的json格式传递给apiserver进行创建、查看、管理的操作。
//帮助信息
[root@localhost bin]# kubectl --help
kubectl controls the Kubernetes cluster manager.Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner):
create Create a resource from a file or from stdin.
expose 使用 replication controller, service, deployment 或者 pod
并暴露它作为一个 新的 Kubernetes Service
run 在集群中运行一个指定的镜像
set 为 objects 设置一个指定的特征Basic Commands (Intermediate):
explain 查看资源的文档
get 显示一个或更多 resources
edit 在服务器上编辑一个资源
delete Delete resources by filenames, stdin, resources and names, or by resources and
label selectorDeploy Commands:
rollout Manage the rollout of a resource
scale 为 Deployment, ReplicaSet, Replication Controller 或者 Job
设置一个新的副本数量
autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController
的副本数量Cluster Management Commands:
certificate 修改 certificate 资源.
cluster-info 显示集群信息
top Display Resource (CPU/Memory/Storage) usage.
cordon 标记 node 为 unschedulable
uncordon 标记 node 为 schedulable
drain Drain node in preparation for maintenance
taint 更新一个或者多个 node 上的 taintsTroubleshooting and Debugging Commands:
describe 显示一个指定 resource 或者 group 的 resources 详情
logs 输出容器在 pod 中的日志
attach Attach 到一个运行中的 container
exec 在一个 container 中执行一个命令
port-forward Forward one or more local ports to a pod
proxy 运行一个 proxy 到 Kubernetes API server
cp 复制 files 和 directories 到 containers 和从容器中复制 files 和
directories.
auth Inspect authorization
1、项目的生命周期
创建–>发布–>更新–>回滚–>删除
2、创建kubectl run命令
- 创建并运行一个或多个容器镜像
- 创建一个deployment或job来管理容器
- kubectl run --help查看使用帮助
启动nginx实例,暴露容器端口80,设置副本数3
kubectl run nginx-deployment --image=nginx:1.14 --port=80 --replicas=3
使用run报错
k8sv1.18.0以后的版本, --replicas以后弃用该命令,推荐使用deployment创建pods
我这里用的是1.21.3版本
- 想创建多个实例时可以使用:kubectl create deployment pg102 --image=pg:12
- –port=5432 --replicas=3 来进行创建;
- 查看pod: kubectl get pod,用来查看使用命令创建的所有实例
- 查看deploy:kubectl get deploy,用来查看实例所创建的数量;
- 高于1.17版本的建议以后直接使用create deployment创建pod管理器方式创建pod;
kubectl create deployment nginx2 --imag