3、kubernetes应用快速入门190625
一、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、使用示例
- 创建2个提供web的pod
~]# kubectl run myapp --image=dongfeimg/myapp:v1 --replicas=2
- 创建一个客户端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
- 为myapp创建一个service
~]# kubectl expose deployment myapp --name=myapp --port=80
- 在client测试,service可以实现轮询调度
[root@client /]# curl myapp/hostname.html
myapp-6fd6445cc6-2hx5h
[root@client /]# curl myapp/hostname.html
myapp-6fd6445cc6-5p676
- 将pod扩展至5个副本
~]# kubectl scale --replicas=5 deployment myapp
- 镜像升级(灰度)
~]# kubectl set image deployment myapp myapp=dongfeimg/myapp:v2
~]# kubectl rollout status deployment myapp #查看更新进度
- 回滚上一版本
~]# 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的更多相关文章
- 4、kubernetes资源清单快速入门190625
一.资源清单概念 资源/对象的类型 工作负载型资源:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob, ... 服务发 ...
- 超长干货丨Kubernetes网络快速入门完全指南
Kubernetes网络一直是一个非常复杂的主题.本文将介绍Kubernetes实际如何创建网络以及如何为Kubernetes集群设置网络. 本文不包括如何设置Kubernetes集群.这篇文章中的所 ...
- Kubernetes 学习4 kubernetes应用快速入门
一.相关命令 1.kubectl 通过连接api server 进行各k8s对象资源的增删改查,如pod,service,controller(控制器),我们常用的pod控制器replicaset,d ...
- kubernetes 应用快速入门
使用kubectl进行增.删.查.改等常用操作 查看kubectl命令帮助 kubectl -h kubectl controls the Kubernetes cluster manager. Fi ...
- Kubernetes快速入门
二.Kubernetes快速入门 (1)Kubernetes集群的部署方法及部署要点 (2)部署Kubernetes分布式集群 (3)kubectl使用基础 1.简介 kubectl就是API ser ...
- 5分钟带你快速入门和了解 OAM Kubernetes
什么是 OAM? OAM 的全称为开放应用模型(Open Application Model),由阿里巴巴宣布联合微软共同推出. OAM 解决了什么问题? OAM 本质是为了解耦K8S中现存的形形色色 ...
- spring boot入门教程——Spring Boot快速入门指南
Spring Boot已成为当今最流行的微服务开发框架,本文是如何使用Spring Boot快速开始Web微服务开发的指南,我们将使创建一个可运行的包含内嵌Web容器(默认使用的是Tomcat)的可运 ...
- Golang快速入门
Go语言简介: Golang 简称 Go,是一个开源的编程语言,Go是从2007年末由 Robert Griesemer, Rob Pike, Ken Thompson主持开发,后来还加入了Ian L ...
- istio部署-快速入门
参考 istio/istio Quick Start Evaluation Install fleeto/sleep fleeto/flaskapp 本文为 istio 快速入门部署,一般用于演示环境 ...
随机推荐
- 2018.5.28 PSOC第一枪:基于cypress的蓝牙开发
Cypress-BLE 开发套件可以快速开发 物联网电子产品. PSOC编程特点: A 拖放各PSoC 组件到工作区中,以设计原理图B 完成各组件之间的布线,并配置GPIOC 使用所包含的组件API ...
- python实现列队
1 列队定义 队列是项的有序结合,其中添加新项的一端称为队尾,移除项的一端称为队首.当一个元素从队尾进入队列时,一直向队首移动,直到它成为下一个需要移除的元素为止. 最近添加的元素必须在队尾等待.集合 ...
- C++ STL, next_permutation用法。
next_permutation 将按字母表顺序生成给定序列的下一个较大的序列,直到整个序列为 #include"iostream" #include"algorithm ...
- ACM学习历程—UVALive 7147 World Cup(分类讨论 && 贪心)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 【LeetCode】081. Search in Rotated Sorted Array II
题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would t ...
- IO系列之File
1 File类 1.1 目录列表器 在这里我主要是参考Think in Java的内容从而做的一些总结以及扩展.Java中的IO流的设计应该说是Java中最经典的,最学院式的设计,包括它的整体架构设计 ...
- 使用showInputDialog显示输入框
------------------siwuxie095 工程名:TestJOptionPane 包名:com.siwuxie095.showd ...
- win7中配置eclipse连接Ubuntu内的hadoop
Hadoop java 分布式 云计算 数据库 目录[-] 1.设置Ubuntu静态IP: 1)配置网卡参数到interfaces文件: 2)重启网卡: 2.配置Ubuntu的hosts: 3.配置V ...
- vue前端+java后端 vue + vuex + koa2开发环境搭建及示例开发
vue + vuex + koa2开发环境搭建及示例开发 https://segmentfault.com/a/1190000012918518 vue前端+java后端 https://blog.c ...
- Entity Framework Code-First(4):Simple Code First Example
Simple Code First Example: Let's assume that we want to create a simple application for XYZ School. ...