Deployment
新建一个pod_nginx.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.12.2
ports:
- containerPort: 80
然后执行如下命令,即可完成创建
kubectl create -f pod_nginx.yml
查看
kubectl get deployment -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-deployment 3 3 3 0 3m nginx nginx:1.12.2 app=nginx
kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-7498dc98f8 3 3 0 2m
kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-7498dc98f8-5687w 0/1 ContainerCreating 0 2m
nginx-deployment-7498dc98f8-f2lbx 0/1 ContainerCreating 0 2m
nginx-deployment-7498dc98f8-f8zwj 0/1 ContainerCreating 0 2m
升级image
kubectl set image deployment nginx-deployment nginx=nginx:1.13
deployment.apps "nginx-deployment" image updated
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-deployment 3 4 1 0 5m nginx nginx:1.13 app=nginx
回滚image
kubectl rollout undo deployment nginx-deployment
deployment.apps "nginx-deployment"
kubectl get deployment -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-deployment 3 4 3 0 7m nginx nginx:1.12.2 app=nginx
Node
查看
kubectl get node -o wide
NAME STATUS ROLES AGE VERSION EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready <none> 2d v1.10.0 <none> Buildroot 2018.05 4.16.14 docker://17.12.1-ce
端口暴露
# 查看
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
# 端口暴露
kubectl expose deployment nginx-deployment --type=NodePort
Error from server (AlreadyExists): services "nginx-deployment" already exists
# 删除旧的
kubectl delete services nginx-deployment
service "nginx-deployment" deleted
# 重新暴露
kubectl expose deployment nginx-deployment --type=NodePort
service "nginx-deployment" exposed
# 再次查看,此时可以在宿主机上使用curl 192.168.99.100:30437访问到web页面
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
nginx-deployment NodePort 10.99.122.148 <none> 80:30437/TCP 15s
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。