➜ kubectl create -f pod.yml pod/k8s-test created ➜ kubectl get pods NAME READY STATUS RESTARTS AGE k8s-test 1/1 Running 0 13s ➜ kubectl describe pods | grep Labels Labels: <none> ➜ kubectl apply -f pod.yml Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply pod/k8s-test configured ➜ kubectl describe pods | grep Labels Labels: app=k8s-test
配置服务Service Service 的作用有点像建立了一个反向代理和负载均衡器,负责把请求分发给后面的 pod
➜ kubectl create -f svc.yml service/k8s-test-svc created ➜ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE k8s-test-svc NodePort 10.107.103.59 <none> 8080:30050/TCP 5s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10d
➜ kubectl create -f deployment.yml deployment.apps/k8s-test-deployment created ➜ kubectl get rs NAME DESIRED CURRENT READY AGE k8s-test-deployment-75958fb65d 10 10 10 40s ➜ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE k8s-test-deployment 10/10 10 10 2m49s
➜ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main ➜ docker build -t k8s-test:0.2 . Sending build context to Docker daemon 30.59MB Step 1/7 : FROM alpine:latest ---> a24bb4013296 Step 2/7 : LABEL maintainer="liion" ---> Using cache ---> 076011b6935a Step 3/7 : ADD main / ---> 1d328bb849d4 Step 4/7 : RUN chmod +x /main ---> Running in 66e8b70c65e8 Removing intermediate container 66e8b70c65e8 ---> 42fdf5cc92a8 Step 5/7 : WORKDIR / ---> Running in 7c55500f2990 Removing intermediate container 7c55500f2990 ---> 85c301d1da3c Step 6/7 : EXPOSE 8080 ---> Running in 505734fdd2fe Removing intermediate container 505734fdd2fe ---> d33ce9247036 Step 7/7 : CMD ["./main"] ---> Running in f427fd82e054 Removing intermediate container f427fd82e054 ---> 24eb5672269b Successfully built 24eb5672269b Successfully tagged k8s-test:0.2 ➜ kubectl apply -f deployment.yml --record=true Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply deployment.apps/k8s-test-deployment configured ➜ kubectl get pods NAME READY STATUS RESTARTS AGE k8s-test-deployment-69ff46fd95-4tw7s 1/1 Running 0 4s k8s-test-deployment-69ff46fd95-5tqwz 1/1 Running 0 16s k8s-test-deployment-69ff46fd95-7zpdq 1/1 Running 0 4s k8s-test-deployment-69ff46fd95-85w7m 1/1 Running 0 16s k8s-test-deployment-75958fb65d-67bqq 1/1 Running 0 31m k8s-test-deployment-75958fb65d-fx4pl 1/1 Running 0 31m k8s-test-deployment-75958fb65d-l7vmm 1/1 Running 0 31m k8s-test-deployment-75958fb65d-lr2kj 1/1 Running 0 31m k8s-test-deployment-75958fb65d-ng7k8 1/1 Running 0 31m k8s-test-deployment-75958fb65d-ts79t 1/1 Running 0 31m k8s-test-deployment-75958fb65d-xvrps 1/1 Running 0 31m ➜ kubectl rollout status deployment k8s-test-deployment Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... deployment "k8s-test-deployment" successfully rolled out
➜ kubectl rollout undo deployment k8s-test-deployment --to-revision=1 deployment.apps/k8s-test-deployment rolled back ➜ kubectl rollout status deployment k8s-test-deployment Waiting for deployment "k8s-test-deployment" rollout to finish: 2 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 8 out of 10 new replicas have been updated... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... Waiting for deployment "k8s-test-deployment" rollout to finish: 1 old replicas are pending termination... deployment "k8s-test-deployment" successfully rolled out