当前位置:网站首页>kubernetes集群命令行工具kubectl
kubernetes集群命令行工具kubectl
2022-06-28 07:36:00 【有勇气的牛排】
1 kubectl 概述
kubectl是Kubernetes集群的命令行工具,通过kubectl能够对集群本身进行管理,并能够在集群上进行容器话应用安装部署。
2 kubernetes命令
2.1 kubectl 命令的语法
kubectl [common] [TYPE] [NAME] [flags]
(1)comand:指定要对资源执行的操作,例如 create、get、describe和delete
(2)TYPE:指定资源的类型,资源类型是大小写敏感的,开发者能够以单数、复数和缩略的形式,例如:
kubectl get pod pod1
kubectl get pods pod1
kubectl get po pod1
(3)NAME:指定资源的名称,名称也大小写敏感的。如果省略名称,则会显示所有的资源。
kubectl get pods
(4)flags:指定可选的参数。例如:可用-s或者-server参数指定Kubernetes API Server的地址和端口。
kubectl get node
kubectl get nodes
kubectl get nodes master

帮助命令kubectl --help
具体查看某个操作
kubectl get --help
2.2 常用命令
nginx为例
创建nginx pod
kubectl create deployment nginx --image=nginx
对外暴露端口
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod, svc

查看当前健康状态
kubectl get cs
3 使用命令
3.1 查
查pods
# 查看所有pods 指定命名空间
kubectl get pods --all-namespaces
查service
# 查所有service
kubectl get service
3.2 Deployment 操作
查看
kubectl get deployment
删除
kubectl get deployment
kubectl delete deployment flask-demo
或者
kubectl delete-f app.yaml
4 项目部署
vim app.yaml
# 1 部署信息
apiVersion: apps/v1
kind: Deployment # 采用deployment部署
metadata:
name: flask-demo
namespace: default # 默认命名空间
labels:
app: flask-demo
spec:
replicas: 2 # 副本设置1个
selector:
matchLabels:
app: flask-demo
template:
metadata:
labels:
app: flask-demo
spec:
containers: #容器相关配置
- name: flask-demo-app
image: vitcloud/flask_demo:latest # 镜像地址
ports: # 容器暴露端口
- containerPort: 80
resources: # 容器所要使用的资源
requests:
cpu: "1000m"
memory: "1Gi"
limits:
cpu: "2000m"
memory: "2Gi"
# service 信息 --- 同部署关联
apiVersion: v1
kind: Service
metadata:
name: flask-demo-service
spec:
selector: # ====对应
app: flask-demo # 指向pod
type: NodePort # 通过端口开放服务
ports:
- name: web
port: 80
protocol: TCP
# targetPort: 80 # 容器端口
# nodePort: 30001 # 对外暴露端口
指定文件
kubectl apply -f app.yaml
# 查看
kubectl get pods --all-namespaces -o wide
# 查看进度
watch kubectl get pods --all-namespaces -o wide
# 查看资源详情
kubectl describe pods flask-demo-77f769cb94-7pw4q
边栏推荐
- A gadget can write crawlers faster
- 阿里云服务器创建快照、回滚磁盘
- Recommended system series (Lecture 5): Optimization Practice of sorting model
- MMR rearrangement (similarity is calculated by editing distance and repeatability)
- PLC -- 笔记
- Sword finger offer|: linked list (simple)
- Implementation of commit message standardized control in large projects
- Leetcode+ 66 - 70 high precision, two sub topics
- Makefile
- Unity UI shadow component
猜你喜欢

Leetcode+ 66 - 70 high precision, two sub topics

ACM笔记

Design and practice of vivo sensitive word matching system

What should I do if the version is incompatible with the jar package conflict?

Principle and practice of bytecode reference detection

The practice of traffic and data isolation in vivo Reviews

Section VII starting principle and configuration of zynq

Introduction and several months' experience of extending the solution thanos of Prometheus

goland IDE和delve调试位于kubernetes集群中的go程序
![[ thanos源码分析系列 ]thanos query组件源码简析](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[ thanos源码分析系列 ]thanos query组件源码简析
随机推荐
Alibaba cloud server creates snapshots and rolls back disks
Open62541 import nodeset file directly
QT -- communication protocol
Construction and exploration of vivo database and storage platform
代码提交规范
Encyclopedia of scala operators
Evolution of vivo push platform architecture
在idea中,get和set方法爆红可能是没有安装Lombok插件
es6箭头函数中return的用法
R 语言 Hitters 数据分析
Mysql8.0和Mysql5.0访问jdbc连接
2021 VDC: technological architecture evolution of vivo Internet service for 100 million users | PPT download attached
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
[thanos source code analysis series]thanos query component source code analysis
R language ggmap
MySQL installation steps - how to create a virtual machine under Linux (1)
R语言绘制 ggplot2 季节性图
In idea, the get and set methods may be popular because the Lombok plug-in is not installed
Top 25 most popular articles on vivo Internet technology in 2021
PLC -- 笔记