#创建删除名称空间
kubectl create ns hello
kubectl delete ns hello
#yaml文件创建名称空间
vi pod.yaml
apiVersion: v1
kind: Namespace
metadata:
name: hello
kubectl apply -f pod.yaml
kubectl delete -f pod.yaml
#直接运行一个pod
kubectl run mynginx --image=nginx
#yaml文件创建一个pod:mynginx
apiVersion: v1
kind: Pod
metadata:
labels:
run: mynginx
name: mynginx
# namespace: default
spec:
containers:
- image: nginx
name: mynginx
# 查看default名称空间的Pod
kubectl get pod
# 描述
kubectl describe pod 你自己的Pod名字
# 删除
kubectl delete pod Pod名字
# 查看Pod的运行日志
kubectl logs Pod名字
# 每个Pod - k8s都会分配一个ip
kubectl get pod -owide
# 使用Pod的ip+pod里面运行容器的端口
curl 192.168.169.136
# 集群中的任意一个机器以及任意的应用都能通过Pod分配的ip来访问这个Pod
#deployment部署pod具有自愈能力
kubectl create deployment mytomcat --image=tomcat:8.5.68
# --replicas=3部署多个pod
kubectl create deployment my-dep --image=nginx --replicas=3
#yaml文件创建如下
/*
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: my-dep
name: my-dep
spec:
replicas: 3
selector:
matchLabels:
app: my-dep
template:
metadata:
labels:
app: my-dep
spec:
containers:
- image: nginx
name: nginx
*/
#扩缩容pod
kubectl scale --replicas=5 deployment/my-dep
#也可以通过修改yaml文件实现
kubectl edit deployment my-dep
#不停机更新版本
kubectl set image deployment/my-dep nginx=nginx:1.16.1 --record
kubectl rollout status deployment/my-dep
#退回版本
#历史记录
kubectl rollout history deployment/my-dep
#查看某个历史详情
kubectl rollout history deployment/my-dep --revision=2
#回滚(回到上次)
kubectl rollout undo deployment/my-dep
#回滚(回到指定版本)
kubectl rollout undo deployment/my-dep --to-revision=2