K8S
架构
Kubernetes Master
- API Server
- Scheduler
- Controller Manager
- replication
- namespace controller
- Etcd
- Network
- Flannel
- Calico
- Canal
- Node’s Components
Node
- Kubelet
- Kube-proxy
- Docker
Pod
- Kubernetes最小工作单元
- 运行在一个Node上
- Pod中的容器共享网络和存储
Controller
- Deployment
- ReplicaSet
- DaemonSet
- StatefulSet
- Job
环境搭建
公共安装
- yum
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF
- Set SELinux in permissive mode
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
- 安装
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
- 启动
systemctl enable kubelet
systemctl restart kubelet
Master节点
kubeadm init --apiserver-advertise-address=192.168.150.111 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl applay -f https://raw.githubusercontentcom/coreos/flannel/master/Documentation/kube-flannel.yml
Slave节点
kubeadm join 192.168.150.111 --token
容器编排
部署pod
- 编辑pod.yaml配置文件
apiVersion: v1
kind: Pod
metadata:
name: testnginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
- 配置资源
kubectl apply -f pod.yaml
部署deployment
- 编辑deployment.yaml配置文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: testnginx
spec:
replicas: 3
template:
metadata:
labels:
app: web_server
spec:
containers:
- name: nginx
image: nginx:1.7.9
- 配置资源
kubectl apply -f deployment.yaml
服务发现与负载均衡
- Pod访问方式
- ClusterIP Service(内部)
- NodePort Service(由内而外)
- LoadBalancer Service(外部)
- Ingress(外部)
- Pod内部服务调用:localhost:容器内应用端口
- Pod间服务调用:服务名.namespace名:服务端口
- 外部服务调用:负载均衡IP:负载均衡器内映射端口或Ingress URL
存储
Volume
- 分配方式
- emptyDir
- hostPath
- storage provider
- PV -> PVC
- PV动态供给
配置
创建方式
- from-literal
- from-file
- from-env-file
- yaml
传递方式
- volumes
- env
认证和授权
认证
- 普通用户User
- 服务账号Service Account
- 客户端证书
- 静态密码文件
- Token
授权
- RBAC(Role-Based Access Control)
- Role
- ClusterRole
集群监控
监控纬度
- 应用性能管理(APM)-Metrics
- 业务追踪-Tracing
- 日志管理
Prometheus
ELK->EFK
弹性扩缩容
云平台实现
常用命令
- kubectl get node:获取集群节点
- kubectl get pod:获取集群pod
- kubectl get deployment:获取集群deployment
- kubectl describe pod:查看指定pod详细信息
- kubectl describe deployment:查看指定deployment详细信息
- kubectl edit:动态修改配置
- kubectl scale:扩容/缩容