You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
2.1 KiB
Markdown
173 lines
2.1 KiB
Markdown
# Kubernetes
|
|
|
|
## Namespace
|
|
> 只隔离资源 不隔离网络
|
|
|
|
- 查看
|
|
```shell
|
|
kubectl get namespace/ns
|
|
```
|
|
|
|
- 创建
|
|
```shell
|
|
# 创建配置文件
|
|
vi hello-namespace.yml
|
|
|
|
apiVersion: v1
|
|
kind: Namespace
|
|
metadata:
|
|
name: hello-namespace
|
|
```
|
|
```shell
|
|
kubectl apply -f hello-namespace.yml
|
|
```
|
|
|
|
- 删除
|
|
```shell
|
|
kubectl delete -f hello-namespace.yml
|
|
```
|
|
## Pod
|
|
> 是多个容器的组合
|
|
|
|
- 查看
|
|
```shell
|
|
kubectl get pod [-n <namespace>/ -A] [-owide]
|
|
```
|
|
|
|
- 创建
|
|
```shell
|
|
vi hello-niginx.yml
|
|
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
labels:
|
|
run: hello-nginx
|
|
name: hello-nginx
|
|
# namespace: default
|
|
spec:
|
|
containers:
|
|
- image: nginx
|
|
name: hello-nginx
|
|
```
|
|
```shell
|
|
kubectl apply -f hello-niginx.yml
|
|
```
|
|
|
|
- 删除
|
|
```shell
|
|
kubectl delete -f hello-niginx.yml
|
|
```
|
|
## Deployment
|
|
|
|
- 查看
|
|
```shell
|
|
kubectl get deploys [-n <namespace>/ -A]
|
|
```
|
|
|
|
- 创建
|
|
```shell
|
|
vi hello-deploy.yml
|
|
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
labels:
|
|
app: hello-deploy
|
|
name: hello-deploy
|
|
spec:
|
|
replicas: 3 # 创建三个副本
|
|
selector:
|
|
matchLabels:
|
|
app: hello-deploy
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: hello-deploy
|
|
spec:
|
|
containers:
|
|
- image: nginx
|
|
name: hello-nginx
|
|
```
|
|
```shell
|
|
kubectl apply -f hello-deploy.yml
|
|
```
|
|
|
|
- 删除
|
|
```shell
|
|
kubectl delete -f hello-deploy.yml
|
|
```
|
|
|
|
## Pod
|
|
|
|
### 查看
|
|
|
|
查看指定命名空间的 pod
|
|
|
|
```shell
|
|
kubectl get pods -n default
|
|
kubectl get pods -n kube-system
|
|
```
|
|
|
|
查看所有命名空间的 pod
|
|
|
|
```shell
|
|
kubectl get pods -A
|
|
```
|
|
|
|
查看 pod 详细信息
|
|
|
|
```shell
|
|
kubectl get pods -o wide -A
|
|
```
|
|
|
|
实时监控 pod 详细信息
|
|
|
|
```shell
|
|
kubectl get pods -o wide -A -w
|
|
```
|
|
|
|
描述 pod 详细信息
|
|
|
|
```shell
|
|
kubectl describe pod xxxxx
|
|
```
|
|
|
|
|
|
查看 pod 命名帮助信息
|
|
|
|
```shell
|
|
kubectl get pods --help
|
|
```
|
|
|
|
### 创建
|
|
|
|
命令行创建
|
|
|
|
```shell
|
|
kubectl run nginx --image=nginx
|
|
```
|
|
|
|
创建路径
|
|
|
|
```shell
|
|
mkdir -p /usr/local/kubernetes/config/ && cd /usr/local/kubernetes/config/
|
|
```
|
|
|
|
配置文件创建
|
|
|
|
```shell
|
|
|
|
cat > nginx-pod.yml <<'EOF'
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: nginx
|
|
spec:
|
|
containers:
|
|
- name: nginx
|
|
image: nginx
|
|
ports:
|
|
- containerPort: 80
|
|
EOF
|
|
``` |