1. 编写pod配置文件
    petclinic-pod.yml:
apiVersion: v1
kind: Pod
metadata:
  name:  petclinic
spec:
  containers:
    - name: petclinic
      image: spring2go/spring-petclinic:1.0.0.RELEASE
  1. 拉取要部署的镜像(免得等下部署的时候慢)
docker  pull spring2go/spring-petclinic:1.0.0.RELEASE
  1. 查看当前k8s 集群状态

kubectl  get all

返回

 ~/Coollf/k8s  kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   21m
  1. 部署pod
kubectl  apply -f petclinic-pod.yml

返回:

 ~/Coollf/k8s  kubectl  apply -f petclinic-pod.yml
pod/petclinic created
  1. 再次查看k8s 集群状态
kubectl get all

返回:

 ~/Coollf/k8s  kubectl get all
NAME            READY   STATUS    RESTARTS   AGE
pod/petclinic   1/1     Running   0          36s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   14m
  1. 查看pod 想想信息
 kubectl describe pod petclinic

返回:

 ~/Coollf/k8s  kubectl describe pod petclinic
Name:         petclinic
Namespace:    default
Priority:     0
Node:         docker-desktop/192.168.65.3
Start Time:   Sun, 28 Feb 2021 13:08:52 +0800
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           10.1.0.23
IPs:
  IP:  10.1.0.23
Containers:
  petclinic:
    Container ID:   docker://174e190beaf8f2cab173995b44962e73729f2d843e34277690de1a0452f08a39
    Image:          spring2go/spring-petclinic:1.0.0.RELEASE
    Image ID:       docker-pullable://spring2go/spring-petclinic@sha256:e207ce909cdc67ba07605c77b03f8f4abd3607ae35ec5d7220c7d5c21932b08b
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 28 Feb 2021 13:08:53 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mv6nc (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-mv6nc:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mv6nc
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  118s  default-scheduler  Successfully assigned default/petclinic to docker-desktop
  Normal  Pulled     117s  kubelet            Container image "spring2go/spring-petclinic:1.0.0.RELEASE" already present on machine
  Normal  Created    117s  kubelet            Created container petclinic
  Normal  Started    117s  kubelet            Started container petclinic

重点关注 Event , 即pod 的事件

  1. 进行端口转发,进行调试
kubectl port-forward petclinic 8080:8080

把本地的8080端口转发到 petclinic pod 的 8080 端口中

  1. 删除pod
 kubectl delete pod petclinic