K8s 学习笔记1 - 基本应用

k8s基本信息

$ minikube version
minikube version: v0.28.2

$ minikube start
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.0", GitCommit:"91e7b4fd31fcd3d5f436da26c980becec37ceefe", GitTreeState:"clean", BuildDate:"2018-06-27T20:17:28Z", GoVersion:"go1.10.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-04-10T12:46:31Z", GoVersion:"go1.9.4", Compiler:"gc", Platform:"linux/amd64"}

$ kubectl cluster-info
Kubernetes master is running at https://172.17.0.27:8443

创建集群

#创建集群
$ kubectl get nodes
NAME       STATUS    ROLES     AGE       VERSION
minikube   Ready         31s       v1.10.0

#获取服务名
$ hostname
minikube

#
$ kubectl cluster-info
Kubernetes master is running at https://172.17.0.27:8443

部署应用

$ kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080
deployment.apps/kubernetes-bootcamp created

$ kubectl get pods
NAME                                  READY     STATUS    RESTARTS   AGE
kubernetes-bootcamp-56cdd766d-ztg4l   1/1       Running   0          33s

访问应用

$ kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
service/kubernetes-bootcamp exposed

$ kubectl get services
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.96.0.1                443/TCP          4m
kubernetes-bootcamp   NodePort    10.100.242.178           8080:31477/TCP   12s

$ curl minikube:31477
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-56cdd766d-ztg4l | v=1

scale 应用

$ kubectl get deployments
NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   1         1         1            1           3m

$ kubectl scale deployments/kubernetes-bootcamp --replicas=3
deployment.extensions/kubernetes-bootcamp scaled

$ kubectl get deployments
NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   3         3         3            3           4m

$ curl minikube:31477
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-56cdd766d-ztg4l | v=1

$ curl minikube:31477
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-56cdd766d-cqmwc | v=1

$ curl minikube:31477
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-56cdd766d-5q5d8 | v=1

$ kubectl scale deployments/kubernetes-bootcamp --replicas=2
deployment.extensions/kubernetes-bootcamp scaled

滚动更新

$ kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
deployment.extensions/kubernetes-bootcamp image updated

$ kubectl get pods
NAME                                   READY     STATUS        RESTARTS   AGE
kubernetes-bootcamp-56cdd766d-cqmwc    1/1       Terminating   0          3m
kubernetes-bootcamp-56cdd766d-ztg4l    1/1       Terminating   0          7m
kubernetes-bootcamp-7799cbcb86-bnncq   1/1       Running       0          18s
kubernetes-bootcamp-7799cbcb86-h2gq8   1/1       Running       0          19s

$ curl minikube:31477
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7799cbcb86-bnncq | v=2

$ curl minikube:31477
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7799cbcb86-h2gq8 | v=2

$ kubectl rollout undo deployments/kubernetes-bootcamp
deployment.extensions/kubernetes-bootcamp

$ kubectl get pods
NAME                                   READY     STATUS        RESTARTS   AGE
kubernetes-bootcamp-56cdd766d-dbk86    1/1       Running       0          7s
kubernetes-bootcamp-56cdd766d-nrd6n    1/1       Running       0          9s
kubernetes-bootcamp-7799cbcb86-bnncq   1/1       Terminating   0          1m
kubernetes-bootcamp-7799cbcb86-h2gq8   1/1       Terminating   0          1m

你可能感兴趣的:(K8s 学习笔记1 - 基本应用)