一、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. listen and translation exercise 49

    Huh? Appears to Be Universally Understood What's the most universal utterance in languages across th ...

  2. C++中getline的用法

    在看紫皮书的时候看到getline,然后查了查具体用法,记录下来. #include"iostream" #include"string" using name ...

  3. Java集合操作类Collections的一些常用方法

    public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); ...

  4. xcopy语法

    xcopy语法 2007-02-09 13:29:45| 分类: 服务器 | 标签:xcopy语法 |字号 订阅复制文件和目录,包括子目录. 语法 xcopySource [Destination] ...

  5. 洛谷【P1561】[USACO12JAN]爬山Mountain Climbing

    我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html 题目传送门:https://www.luogu.org/problemn ...

  6. vi查找替换命令详解

    一.查找 查找命令 /pattern<Enter> :向下查找pattern匹配字符串 ?pattern<Enter>:向上查找pattern匹配字符串 使用了查找命令之后,使 ...

  7. poj 2105 IP Address(水题)

    一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...

  8. mongodb 的命令操作(转)

    成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表  show collections:显 ...

  9. 【转】 Pro Android学习笔记(五二):ActionBar(5):list模式

    可以在action bar中加入spinner的下来菜单,有关spinner,可以参考Pro Android学习笔记(二十):用户界面和控制(8):GridView和Spinner. list的样式和 ...

  10. Hdu 4762 网络赛 高精度大数模板+概率

    注意题目中的这句话he put the strawberries on the cake randomly one by one,第一次选择草莓其实有N个可能,以某一个草莓为开头,然后顺序的随机摆放, ...