一、kubernetes应用入门

1、kubectl命令

  • Basic Commands
  create         Create a resource from a file or from stdin.
expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
run Run a particular image on the cluster
set Set specific features on objects
explain Documentation of resources
get Display one or many resources
edit Edit a resource on the server
delete Delete resources by filenames, stdin, resources and names, or by resources and label selector
  • Deploy Commands
  rollout        Manage the rollout of a resource
scale Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job
autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController
  • Cluster Management Commands
  certificate    Modify certificate resources.
cluster-info Display cluster info
top Display Resource (CPU/Memory/Storage) usage.
cordon Mark node as unschedulable
uncordon Mark node as schedulable
drain Drain node in preparation for maintenance
taint Update the taints on one or more nodes
  • Troubleshooting and Debugging Commands
  describe       Show details of a specific resource or group of resources
logs Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward Forward one or more local ports to a pod
proxy Run a proxy to the Kubernetes API server
cp Copy files and directories to and from containers.
auth Inspect authorization
  • Advanced Commands
  diff           Diff live version against would-be applied version
apply Apply a configuration to a resource by filename or stdin
patch Update field(s) of a resource using strategic merge patch
replace Replace a resource by filename or stdin
wait Experimental: Wait for a specific condition on one or many resources.
convert Convert config files between different API versions
kustomize Build a kustomization target from a directory or a remote url.
  • Settings Commands
  label          Update the labels on a resource
annotate Update the annotations on a resource
completion Output shell completion code for the specified shell (bash or zsh)
  • Other Commands
  api-resources  Print the supported API resources on the server
api-versions Print the supported API versions on the server, in the form of "group/version"
config Modify kubeconfig files
plugin Provides utilities for interacting with plugins.
version Print the client and server version information

2、k8s使用快速入门

  • kubectl run和delete:创建一个deployment或者job控制器控制启动的容器
~]# kubectl run nginx-deploy --image=nginx:1.14 --port=80 --replicas=2
--port=80:端口暴露
--replicas=2:副本个数
--dry-run=true:干跑一次
~]# kubectl delete pods nginx-deploy-bc9ff65dd-lj9bg #删除pods,控制器会自动再起一个,让副本保持在2个
  • kubectl expose:创建service服务,为pod提供固定访问端点
~]# kubectl expose deployment nginx-deploy --name nginx-service --port=80 --target-port=80 --protocol=TCP
deployment nginx-deploy:指定暴露的控制器下的pod
--name nginx-service:service名称
--port=80:service端口
--target-port=80:后端pod端口
--protocol=TCP:协议
  • kubectl get:获取资源信息
~]# kubectl get deployment
~]# kubectl get pods
~]# kubectl get pods -o wide #查看pod运行的详细信息
~]# kubectl get pods --show-labels #显示标签
~]# kubectl get pods -n kube-system -o wide #显示system名称空间的详细信息
~]# kubectl get svc #获取当前集群的svc
~]# kubectl get svc -n kube-system -o wide
  • kubectl edit:修改编辑资源
~]# kubectl edit svc nginx-service
  • kubectl describe:查看资源的详细信息
~]# kubectl describe svc nginx-service  #查询svc的详细信息
  • kubectl scale:扩展/缩减副本pod
~]# kubectl scale --replicas=3 deployment nginx-deploy
  • kubectl set:灰度升级镜像版本
  • kubectl rollout:回滚

3、使用示例

  1. 创建2个提供web的pod
~]# kubectl run myapp --image=dongfeimg/myapp:v1 --replicas=2
  1. 创建一个客户端pod
~]# kubectl run client --image=centos --replicas=1 -it --restart=Never
[root@client /]# curl 10.244.1.3
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
[root@client /]# curl 10.244.1.3/hostname.html
myapp-6fd6445cc6-5p676
  1. 为myapp创建一个service
~]# kubectl expose deployment myapp --name=myapp --port=80
  1. 在client测试,service可以实现轮询调度
[root@client /]# curl myapp/hostname.html
myapp-6fd6445cc6-2hx5h
[root@client /]# curl myapp/hostname.html
myapp-6fd6445cc6-5p676
  1. 将pod扩展至5个副本
~]# kubectl scale --replicas=5 deployment myapp
  1. 镜像升级(灰度)
~]# kubectl set image deployment myapp myapp=dongfeimg/myapp:v2
~]# kubectl rollout status deployment myapp #查看更新进度
  1. 回滚上一版本
~]# kubectl rollout undo deployment myapp

4、补充:配置为可在集群外访问service

~]# kubectl edit svc myapp
type: NodePort
~]# kubectl get svc
myapp NodePort 10.96.37.191 <none> 80:30804/TCP 17m
在集群外访问:http://${NODE_IP}:30804

3、kubernetes应用快速入门190625的更多相关文章

  1. 4、kubernetes资源清单快速入门190625

    一.资源清单概念 资源/对象的类型 工作负载型资源:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob, ... 服务发 ...

  2. 超长干货丨Kubernetes网络快速入门完全指南

    Kubernetes网络一直是一个非常复杂的主题.本文将介绍Kubernetes实际如何创建网络以及如何为Kubernetes集群设置网络. 本文不包括如何设置Kubernetes集群.这篇文章中的所 ...

  3. Kubernetes 学习4 kubernetes应用快速入门

    一.相关命令 1.kubectl 通过连接api server 进行各k8s对象资源的增删改查,如pod,service,controller(控制器),我们常用的pod控制器replicaset,d ...

  4. kubernetes 应用快速入门

    使用kubectl进行增.删.查.改等常用操作 查看kubectl命令帮助 kubectl -h kubectl controls the Kubernetes cluster manager. Fi ...

  5. Kubernetes快速入门

    二.Kubernetes快速入门 (1)Kubernetes集群的部署方法及部署要点 (2)部署Kubernetes分布式集群 (3)kubectl使用基础 1.简介 kubectl就是API ser ...

  6. 5分钟带你快速入门和了解 OAM Kubernetes

    什么是 OAM? OAM 的全称为开放应用模型(Open Application Model),由阿里巴巴宣布联合微软共同推出. OAM 解决了什么问题? OAM 本质是为了解耦K8S中现存的形形色色 ...

  7. spring boot入门教程——Spring Boot快速入门指南

    Spring Boot已成为当今最流行的微服务开发框架,本文是如何使用Spring Boot快速开始Web微服务开发的指南,我们将使创建一个可运行的包含内嵌Web容器(默认使用的是Tomcat)的可运 ...

  8. Golang快速入门

    Go语言简介: Golang 简称 Go,是一个开源的编程语言,Go是从2007年末由 Robert Griesemer, Rob Pike, Ken Thompson主持开发,后来还加入了Ian L ...

  9. istio部署-快速入门

    参考 istio/istio Quick Start Evaluation Install fleeto/sleep fleeto/flaskapp 本文为 istio 快速入门部署,一般用于演示环境 ...

随机推荐

  1. chrome浏览器的跨域设置-包括版本49前后两种设置 ,windows&mac

    做前后分离的webapp开发的时候,出于一些原因往往需要将浏览器设置成支持跨域的模式,好在chrome浏览器就是支持可跨域的设置,网上也有很多chrome跨域设置教程.但是新版本的chrome浏览器提 ...

  2. 用JavaScript实现表单按回车自动提交

    JavaScript实现表单form1按回车自动提交代码如下: <script type="text/javascript"> function submitMe() ...

  3. SPOJ Query on a tree II (树剖||倍增LCA)(占位)

    You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, ...

  4. 洛谷 P1187 3D模型

    题目描述 一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成.在每个网格上都可以有一个建筑,建筑由若干个1×1×1的立方体搭建而成(也就是所有建筑的底部都在同一平面上的).几个典型的城市模 ...

  5. Aravis 库编译方法

    Aravis 库编译方法 March 21, 2015 9:40 PM 首先下载 aravis 库的源代码:aravis 库下载地址 这里我们使用的是 aravis_0_2_0,比较老的一个版本. 首 ...

  6. Guice总结

    Guice总结 Jar包:guice-4.1.0.jar 辅包: guava-15.0.jar aopalliance-.jar javaee-api-6.0-RC2.jar Guice的IoC 两种 ...

  7. 编译Python出现Tab,空格的问题

    我们编译python代码时, 经常出现各种因为tab和空格的问题, 例如: IndentationError: unindent does not match any outer indentatio ...

  8. nginx实现带参数目录域名重定向二级域名方法

    本文章介绍了关于nginx实现带参数目录域名重定向二级域名方法,有需要学习的朋友可参考一下. 下面的代码是基于nginx的子目录301到其他域名(URL)的规则.作用是例如访问http://www.p ...

  9. MY_SQLCode

    一.SPC查询 根据日期查询       应用到了随机函数      NEWID()可以随机生成一个列值实现随机抓取记录 CONVERT(varchar(100),列名, 23) AS TestDat ...

  10. event.keyCode 事件属性

    转自:http://www.runoob.com/jsref/event-key-keycode.html <!DOCTYPE html> <html> <head> ...