k8s架构:k8s是一个容器的管理平台
主要功能:
自我修复
服务发现和负载均衡
自动部署和回滚
弹性伸缩
应用场景,适用于微服务架构
================================================
master
api server 通信api,所有通信增删改查的入口
manage controller 控制器,资源对象的管理,比如限制数量为3个pod ,RS副本集是RC的升级版
scheduler 调度,控制容器需要创建在哪个node上
etcd 分布式存储,所有持久化状态信息的存储
=================================================
node1
kubelet 实现对node节点的管理,管理pods,容器,镜像,volume等
kube-proxy 实现网络的代理和负载均衡,实现与servers通讯,相当于nginx,lvs
docker engine 提供底层的容器化,负责节点容器的管理
=================================================
创建测试
kubectl run net-test --image=alpine --replicas=2 sleep 3600
查看pod的情况
kubectl get pod -o wide
查看某个pod的详情
kubectl describe pod pod-name
先生成一个nginx-deployment.yaml文件
kubectl create -f nginx-deployment.yaml
查看deployment
kubectl get deployment
查看某个deployment的详情
kubectl describe deployment nginx-deployment
更新depolyment
--record 参数用于记录日志,方便后期的回滚操作
kubectl set image deployment/nginx-deployment nginx=nginx.1.12.1 --record
查看更新历史记录
kubectl rollout history deployment/nginx-deployment
查看某个版本的操作历史详情
kubectl rollout history deployment/nginx-deployment --revision=1
快速回滚操作
kubectl rollout undo deployment/nginx-deployment
pod的ip会随机变化,但是访问的不是pod id ,而是 service ip ,这个才是vip
查看service
[root@linux-node1 scripts]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
garish-butterfly-mychart ClusterIP 10.1.40.122 80/TCP 10d
kubernetes ClusterIP 10.1.0.1 443/TCP 16d
nginx-service ClusterIP 10.1.178.121 80/TCP 16d
检查组件状态
[root@master ~]# kubectl get componentstatus
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-1 Healthy {"health": "true"}
etcd-2 Healthy {"health": "true"}
etcd-0 Healthy {"health": "true"}
查看node节点
[root@master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
10.0.10.42 Ready 1d v1.8.3
10.0.10.47 Ready 3d v1.8.3
查看帮助信息:
可以一层一层的寻找自己想要的帮助信息
[root@k8s pod]# kubectl explain pod.spec.containers.command
FIELD: command <[]string>
DESCRIPTION:
Entrypoint array. Not executed within a shell. The docker image's
ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME)
are expanded using the container's environment. If a variable cannot be
resolved, the reference in the input string will be unchanged. The
$(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME).
Escaped references will never be expanded, regardless of whether the
variable exists or not. Cannot be updated. More info:
http://kubernetes.io/docs/user-guide/containers#containers-and-commands
更新pod资源
[root@k8s pod]# kubectl apply -f nginx_pod.yaml
pod "nginx-test" configured