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.
2.1 KiB
2.1 KiB
Kubernetes
Namespace
只隔离资源 不隔离网络
- 查看
kubectl get namespace/ns
- 创建
# 创建配置文件
vi hello-namespace.yml
apiVersion: v1
kind: Namespace
metadata:
name: hello-namespace
kubectl apply -f hello-namespace.yml
- 删除
kubectl delete -f hello-namespace.yml
Pod
是多个容器的组合
- 查看
kubectl get pod [-n <namespace>/ -A] [-owide]
- 创建
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
kubectl apply -f hello-niginx.yml
- 删除
kubectl delete -f hello-niginx.yml
Deployment
- 查看
kubectl get deploys [-n <namespace>/ -A]
- 创建
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
kubectl apply -f hello-deploy.yml
- 删除
kubectl delete -f hello-deploy.yml
Pod
查看
查看指定命名空间的 pod
kubectl get pods -n default
kubectl get pods -n kube-system
查看所有命名空间的 pod
kubectl get pods -A
查看 pod 详细信息
kubectl get pods -o wide -A
实时监控 pod 详细信息
kubectl get pods -o wide -A -w
描述 pod 详细信息
kubectl describe pod xxxxx
查看 pod 命名帮助信息
kubectl get pods --help
创建
命令行创建
kubectl run nginx --image=nginx
创建路径
mkdir -p /usr/local/kubernetes/config/ && cd /usr/local/kubernetes/config/
配置文件创建
cat > nginx-pod.yml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
EOF