关于docker:95-Deployment

75次阅读

共计 1930 个字符,预计需要花费 5 分钟才能阅读完成。

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

正文完
 0