In this scenario, you'll learn how to use Kubectl to create and launch Deployments, Replication Controllers and expose them via Services without writing yaml definitions. This allows you to quickly launch containers onto the cluster.

Step 1 - Launch Cluster

To start we need to launch a Kubernetes cluster.

Execute the command below to start the cluster components and download the Kubectl CLI.

minikube start

Wait for the Node to become Ready by checking

kubectl get nodes

Step 2 - Kubectl Run

The run command creates a deployment based on the parameters specified, such as the image or replicas. This deployment is issued to the Kubernetes master which launches the Pods and containers required. Kubectl run_ is similar to docker run but at a cluster level.

The format of the command is kubectl run <name of deployment> <properties>

The following command will launch a deployment called http which will start a container based on the Docker Image katacoda/docker-http-server:latest.

kubectl run http --image=katacoda/docker-http-server:latest --replicas=

You can then use kubectl to view the status of the deployments

kubectl get deployments

To find out what Kubernetes created you can describe the deployment process.

kubectl describe deployment http

The description includes how many replicas are available, labels specified and the events associated with the deployment. These events will highlight any problems and errors that might have occurred.

In the next step we'll expose the running service.

Step 3 - Kubectl Expose

With the deployment created, we can use kubectl to create a service which exposes the Pods on a particular port.

Expose the newly deployed http deployment via kubectl expose. The command allows you to define the different parameters of the service and how to expose the deployment.

Use the following command to expose the container port 80 on the host 8000binding to the external-ip of the host.

kubectl expose deployment http --external-ip="172.17.0.30" --port= --target-port=

You will then be able to ping the host and see the result from the HTTP service.

curl http://172.17.0.30:8000

Step 4 - Kubectl Run and Expose

With kubectl run it's possible to create the deployment and expose it as a single command.

Use the command command to create a second http service exposed on port 8001.

kubectl run httpexposed --image=katacoda/docker-http-server:latest --replicas= --port= --hostport=

You should be able to access it using

curl http://172.17.0.30:8001

Under the covers, this exposes the Pod via Docker Port Mapping. As a result, you will not see the service listed using

kubectl get svc

To find the details you can use docker ps | grep httpexposed

Pause Containers

Running the above command you'll notice the ports are exposed on the Pod, not the http container itself. The Pause container is responsible for defining the network for the Pod. Other containers in the pod share the same network namespace. This improves network performance and allow multiple containers to communicate over the same network interface..

Step 5 - Scale Containers

With our deployment running we can now use kubectl to scale the number of replicas.

Scaling the deployment will request Kubernetes to launch additional Pods. These Pods will then automatically be load balanced using the exposed Service.

The command kubectl scale allows us to adjust the number of Pods running for a particular deployment or replication controller.

kubectl scale --replicas= deployment http

Listing all the pods, you should see three running for the http deployment

kubectl get pods

Once each Pod starts it will be added to the load balancer service. By describing the service you can view the endpoint and the associated Pods which are included.

kubectl describe svc http

Making requests to the service will request in different nodes processing the request.

curl http://172.17.0.30:8000

Kubernetes - Start containers using Kubectl的更多相关文章

  1. 高可用Kubernetes集群-4. kubectl客户端工具

    六.部署kubectl客户端工具 1. 下载 [root@kubenode1 ~]# cd /usr/local/src/ [root@kubenode1 src]# wget https://sto ...

  2. Kubernetes - Deploy Containers Using YAML

    In this scenario, you'll learn how to use Kubectl to create and launch Deployments, Replication Cont ...

  3. kubernetes 实践二:kubectl命令使用

    这里记录kubernetes学习和使用过程中的内容. CentOS7 k8s-1.13 flanneld-0.10 docker-18.06 etcd-3.3 kubectl用法概述 kubectl是 ...

  4. K8S从入门到放弃系列-(4)kubernetes集群之kubectl命令行工具部署

    摘要:随着版本的不断迭代,k8s为了集群安全,集群中趋向采用TLS+RBAC的安全配置方式,所以我们在部署过程中,所有组件都需要证书,并启用RBAC认证. 我们这里采用二进制安装,下载解压后,把对应组 ...

  5. 九、kubernetes命令行工具kubectl

    为了方便在命令行下对集群.节点.pod进行管理,kubernetes官方提供了一个管理命令:kubectl kubectl作为客户端CLI工具,可以让用户通过命令行对Kubernetes集群进行操作. ...

  6. [Kubernetes]安装和配置kubectl

    安装kubectl 安装kubectl比较简单,几条命令即可(#后面为注释内容): #下载最新版本: curl -LO https://storage.googleapis.com/kubernete ...

  7. kubernetes 实战6_命令_Share Process Namespace between Containers in a Pod&Translate a Docker Compose File to Kubernetes Resources

    Share Process Namespace between Containers in a Pod how to configure process namespace sharing for a ...

  8. kubernetes 实战4_命令_Configure Pods and Containers

    Configure Service Accounts for Pods A service account provides an identity for processes that run in ...

  9. Kubernetes源码之旅:从kubectl到API Server

    概述: Kubernetes项目目前依然延续着之前爆炸式的扩张.急需能够理解Kubernetes原理并且贡献代码的软件开发者.学习Kubernetes源码并不容易.Kubernetes是使用相对年轻的 ...

随机推荐

  1. activiti工作流已办和待办查询sql

    最近项目中遇到一个问题,需要activiti的工作流表和业务表关联分页查询,然而我对于工作流的查询并不太熟悉,所以学习并总结如下. 想看看activiti到底怎么查询的待认领和待办.已办的查询sql, ...

  2. Alpha冲刺——第一天

    Alpha第一天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...

  3. 用逗号隔开简单数据保存为csv

    用记事本编辑简单数据,用英文逗号隔开,编辑为多列,保存为.csv文件.可以用Excel打开编辑.

  4. hustoj题目标准xml格式

    具体格式可见google code. 分析了一下发现像<time_limit></time_limit><memory_limit></memory_limi ...

  5. HDU2376Average distance(树形dp|树上任意两点距离和的平均值)

    思路: 引:如果暴力枚举两点再求距离是显然会超时的.转换一下思路,我们可以对每条边,求所有可能的路径经过此边的次数:设这条边两端的点数分别为A和B,那 么这条边被经过的次数就是A*B,它对总的距离和的 ...

  6. iOS- Swift实现UITableView的常见操作

    1.前言   Swift在这就不多介绍了,想必大家都已皆知. 离Swift面世也过了有一个多月的时间. 在闲暇时间我用Swift实现了UITableView的一些常见操作. 基本都是可以用上的,今天在 ...

  7. week1 技术随笔

    类别c 内容c 开始时间s 结束时间e 被打断时间I 总计(min) 9.5 随笔 构建之法福后感 22:00 24:00 7 113 9.6 分析 需求分析 9:00 9:30 2 28 编码 词频 ...

  8. Jenkins系列-Jenkins插件备份

    Jenkins管理插件 为了让所有的插件在 Jenkins 内可用,所有插件的列表可以访问链接 − https://wiki.jenkins-ci.org/display/JENKINS/Plugin ...

  9. linux后台运行之screen和nohup

    3.1 nohup命令 如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令. 该命令可以在你退出帐户/关闭终端之后继续运行相应的进程. nohup就是不挂起的意 ...

  10. array to object

    array to object native js & ES6 https://stackoverflow.com/questions/4215737/convert-array-to-obj ...