kubernetes案例入门

1.1 kubernetes 官网 :

https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-interactive/

1.2 创建 kubernetes 集群 :

 

1.2.1 根据图片提示操作

1.2.2 执行命令

Cluster up and running

We already installed minikube for you. Check that it is properly installed, by running the minikube version command:

minikube version

OK, we can see that minikube is in place.

Start the cluster, by running the minikube start command:

minikube start

Great! You now have a running Kubernetes cluster in your online terminal. Minikube started a virtual machine for you, and a Kubernetes cluster is now running in that VM.

Cluster version

To interact with Kubernetes during this bootcamp we’ll use the command line interface, kubectl. We’ll explain kubectl in detail in the next modules, but for now, we’re just going to look at some cluster information. To check if kubectl is installed you can run the kubectl version command:

kubectl version

OK, kubectl is configured and we can see both the version of the client and as well as the server. The client version is the kubectl version; the server version is the Kubernetes version installed on the master. You can also see details about the build.

minikube version  //查看kubernetes的版本
 

minikube start   // 创建集群


kubectl version   //查看远程管理工具 kubectl 是否安装



 

1.3 创建单节点的 kubernetes 集群

kubectl get nodes 

执行结果

集群的唯一节点minikube,需要注意的是当前执行命令的地方并不是 host01 ,我们是通过 Kubernetes 的命令行工具 kubectl 远程管理集群。 

 

kubectl cluster-info    //查询集群信息

1.3 部署应用

1.3.1 执行命令 :

kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

我们通过 kubectl run 部署一个应用,命名为 kubernetes-bootcamp,

Docker 镜像通过 --image 指定

--port 设置应用对外服务的端口

Deployment 是 Kubernetes 的术语,理解为应用。

Pod  容器的集合,通常我们会将紧密相关的一组容器放到一个Pod中,同一个Pod中的所有容器共享IP地址和|Port空间, 也就是说他们在一个 network namespace中。

Pot 是 Kubernetes 调度的最小单位,同一个Pod中的容器始终被一起调度。

1.3.2 执行命令 :

kubectl get pods  //查看当前的pod

 kubernetes-bootcamp-75bccb7d87-gb6w5 就是应用的 Pod

1.4 访问应用

 默认情况下,所有的Pod 只能在集群内部访问,对于上面的例子,要访问应用只能直接访问容器的 8080 端口,为了能够从外部访问应用,需要将容器的 8080 端口映射到节点端口。

1.4.1 执行命令 

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


kubectl get services   //查看应用被映射到节点的那个端口

 这里有两个 service ,可以将 service 暂时理解为端口映射,

kubernetes 是默认的 service, 暂时不用考虑,kubernetes-bootcamp 是我们应用的 service ,8080 端口已经映射到 minikube 的31623 端口,端口号随机分配,执行如下命令访问应用,

curl minikube:31623

 

1.5 Scale 应用 

默认情况下,应用只能运行一个副本,可以通过 kubectl get deployments 查看副本数

执行如下命令将副本增加到4个

kubectl scale deployments/kubernetes-bootcamp --replicas=4

 

执行 kubectl  get pods  可以看到当前pod 增加到4个

 

通过  curl minikube:31951  访问应用 ,可以看到每次请求发送到不同的 Pod, 四个副本轮询处理 ,这样就实现了负载均衡。 

 

scale down 执行下列命令

kubectl scale deployments/kubernetes-bootcamp --replicas=3

删除副本 

1.6 滚动更新 

执行命令 将器升级到 v2

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

kubectl get pods 多次执行,动态查询 升级过程

 curl minikube:31995 更新完成后,访问新版本的应用

 版本回退 :

kubectl rollout status deployments/kubernetes-bootcamp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Janson666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值