K8s
CI :持续集成
CD :持续交付 D --Delivery
CD :持续部署 D --Deployment
Kubernetes Cluster:
Masters: (3-host 做高可用)
APIServer ,Scheduler ,Controller-Manger
Node:
Kubelet,docker,kube-proxy
Pod,Label,Label Selector
Label:key=value
1.同一个Pod内的多个容器间通信:loopback
2.各Pod之间的通信:
3.Pod与Service之间的通信:
CNI:
flannet:网络配置
calico:网络配置,网络策略
canel:上两个的结合
kubeadm 集群部署软件
每个节点都要安装:kubelet,docker
kubeadm:
1.master,mondes :安装kubelet,kubeadm,docker
2.master:kubadmin init
3.nodes:kubeadm join
github user:kanghaibin2014@163.com passwd:khb!123456
-----------------------------------------
1.下载Docker-ce的repo地址
[root@node01 yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2.kubernetes
[root@node01 yum.repos.d]# cat k8s.repo
[k8s]
name =Centos 8 kubernetes
baseurl = https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
[root@node01 yum.repos.d]# yum install docker-ce kubelet kubeadm kubectl
[root@master yum.repos.d]# vim /usr/lib/systemd/system/docker.service
Environment="HTTPS_PROXY=http://www.ik8s.io:10080"
Environment="HTTPS_PROXY=127.0.0.0/8,172.16.0.0/16"
[root@master yum.repos.d]# systemctl daemon-reload
[root@master yum.repos.d]# cat /proc/sys/net/brid ge/bridge-nf-call-iptables
[root@master ~]# vim /etc/sysconfig/kubelet
[root@master ~]# cat /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
kubeadm config images list命令查看需要的镜像
[root@master /]# kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
节点加入信息:
kubeadm join 172.16.16.14:6443 --token q9pflj.g7qwnhqclebv1qt0 --discovery-token-ca-cert-hash sha256:5bf540e270ca8629bdbfe444408c8fa494f680df2651a7de999b9acb1a11200d
[root@master /]# kubectl get nodes
[root@master /]# kubectl get cs
[root@master /]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-5c98db65d4-qr9lw 1/1 Running 0 19m
coredns-5c98db65d4-xstdx 1/1 Running 0 19m
etcd-master 1/1 Running 0 18m
kube-apiserver-master 1/1 Running 0 18m
kube-controller-manager-master 1/1 Running 0 18m
kube-flannel-ds-amd64-2nv2b 1/1 Running 0 82s
kube-proxy-wdkgl 1/1 Running 0 19m
kube-scheduler-master 1/1 Running 0 18m
kubeadm init 启动一个 Kubernetes 主节点
kubeadm join 启动一个 Kubernetes 工作节点并且将其加入到集群
kubeadm upgrade 更新一个 Kubernetes 集群到新版本
kubeadm config 如果使用 v1.7.x 或者更低版本的 kubeadm 初始化集群,您需要对集群做一些配置以便使用 kubeadm upgrade 命令
kubeadm token 管理 kubeadm join 使用的令牌
kubeadm reset 还原 kubeadm init 或者 kubeadm join 对主机所做的任何更改
3、用kubeadm安装master
kubeadm init这个命令帮助你启动跟Master相关的组件APIServer、Etcd、Scheduler、Controller-Manager等
kubeadm init的参数:
--apiserver-advertise-address string
API Server将要广播的监听地址。如指定为 `0.0.0.0` 将使用缺省的网卡地址。
--apiserver-bind-port int32 缺省值: 6443
API Server绑定的端口
--apiserver-cert-extra-sans stringSlice
可选的额外提供的证书主题别名(SANs)用于指定API Server的服务器证书。可以是IP地址也可以是DNS名称。
--cert-dir string 缺省值: "/etc/kubernetes/pki"
证书的存储路径。
--config string
kubeadm配置文件的路径。警告:配置文件的功能是实验性的。
--cri-socket string 缺省值: "/var/run/dockershim.sock"
指明要连接的CRI socket文件
--dry-run
不会应用任何改变;只会输出将要执行的操作。
--feature-gates string
键值对的集合,用来控制各种功能的开关。可选项有:
Auditing=true|false (当前为ALPHA状态 - 缺省值=false)
CoreDNS=true|false (缺省值=true)
DynamicKubeletConfig=true|false (当前为BETA状态 - 缺省值=false)
-h, --help
获取init命令的帮助信息
--ignore-preflight-errors stringSlice
忽视检查项错误列表,列表中的每一个检查项如发生错误将被展示输出为警告,而非错误。 例如: 'IsPrivilegedUser,Swap'. 如填写为 'all' 则将忽视所有的检查项错误。
--kubernetes-version string 缺省值: "stable-1"
为control plane选择一个特定的Kubernetes版本。
--node-name string
指定节点的名称。
--pod-network-cidr string
指明pod网络可以使用的IP地址段。 如果设置了这个参数,control plane将会为每一个节点自动分配CIDRs。
--service-cidr string 缺省值: "10.96.0.0/12"
为service的虚拟IP地址另外指定IP地址段
--service-dns-domain string 缺省值: "cluster.local"
为services另外指定域名, 例如: "myorg.internal".
--skip-token-print
不打印出由 `kubeadm init` 命令生成的默认令牌。
--token string
这个令牌用于建立主从节点间的双向受信链接。格式为 [a-z0-9]{6}\.[a-z0-9]{16} - 示例: abcdef.0123456789abcdef
--token-ttl duration 缺省值: 24h0m0s
令牌被自动删除前的可用时长 (示例: 1s, 2m, 3h). 如果设置为 '0', 令牌将永不过期。
镜像获取方法:
# 导出配置文件
kubeadm config print init-defaults --kubeconfig ClusterConfiguration > kubeadm.yml
# 国内不能访问 Google,修改为阿里云
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
# 修改版本号
kubernetesVersion: v1.15.0
# 查看所需镜像列表
kubeadm config images list --config kubeadm.yml
# 拉取镜像
kubeadm config images pull --config kubeadm.yml
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-apiserver:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-controller-manager:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-scheduler:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-proxy:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/pause:3.1
[config/images] Pulled registry.aliyuncs.com/google_containers/etcd:3.3.10
[config/images] Pulled registry.aliyuncs.com/google_containers/coredns:1.3.1
重新打标签:
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.15.0 k8s.gcr.io/kube-apiserver:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.15.0 k8s.gcr.io/kube-controller-manager:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.15.0 k8s.gcr.io/kube-scheduler:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.15.0 k8s.gcr.io/kube-proxy:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
master节点所镜像:
kang037/kube-proxy:v1.15.0
kang037/kube-apiserver:v1.15.0
kang037/kube-scheduler:v1.15.0
kang037/kube-controller-manager:v1.15.0
kang037/coredns:1.3.1
kang037/etcd:3.3.10
kang037/pause:3.1
node节点镜像
k8s.gcr.io/kube-proxy:v1.15.0
quay.io/coreos/flannel:v0.11.0-amd64
k8s.gcr.io/pause:3.1
以上镜像可通过阿里运下载后重新打标签即可
----------------------------------------------------------------
网络配置:
master:
1.kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml
nodes:
1.docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.15.0
docker pull quay.io/coreos/flannel:v0.11.0-amd64
docker pull registry.aliyuncs.com/google_containers/pause:3.1
2.docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.15.0 k8s.gcr.io/kube-proxy:v1.15.0
docker tag registry.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
创建sevice服务,固定访问入口
Usage:
kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name]
[--name=name] [--external-ip=external-ip-of-service] [--type=type] [options]
[root@master /]# kubectl expose deployment nginx-deploy --name=nginx --port=80 --target-port=80 --protocol=TCP
[root@master /]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 102m
nginx ClusterIP 10.104.230.21 <none> 80/TCP 52s
[root@master /]# kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 106m
查看service信息:
[root@master ~]# kubectl describe svc nginx
查看pod标签信息
[root@master ~]# kubectl get pods --show-labels
创建资源的方法:
apiserver仅接收JSON格式的资源定义;
yaml格式提供配置清单,apiserver可自动将期转为json格式 ,而后提交
[root@master /]# kubectl explain pods.metadata/kind/spec/apiserver/status 查看定义说明
大部分资源的配置清单:
apiserver:group/version
$kubectl api-versions
kind:资源类别
metadata:元数据
mane
namespace
labels
annotations
每个资源的引用PATH: /api/GROUP/VERSION/namespace/NAMESPACE/TYPE/NAME
示例:
selfLink: /api/v1/namespaces/default/pods/nginx-deploy-7689897d8d-n9b2z
spec:定义成用户期望的状态,disired state
status:当前状态,current state ,本字段由kubernetes集群维护
标签:key = value
key:字母或数字、下划线开头
value:可以为空,字母或数字开头和结尾
pod状态:
1.Pending 挂起
2.Running 运行
3.Faile 失败
4.Succeeded 成功
5.Uuknown
创建pod:
POD探针类型三种 :ExecAction,
根据yaml文创建pod
[root@master ~]# cat nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-nginx-pod
namespace: default
spec:
containers:
- name: liveness-nginx-container
image: nginx:alpine
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","touch /tmp/healthy;sleep 30;rm -f /tmp/healthy; sleep 600"]
livenessProbe:
exec:
command: ["test","-e","/tmp/healthy"]
initialDelaySeconds: 2
periodSeconds: 3
[root@master ~]# kubectl create -f nginx.yaml
pod/liveness-nginx-pod created
kubectl exec -it PodName -- /bin/sh 接入到已运行的PodName,执行/bin/sh命令
[root@master ~]# kubectl explain pods.spec.containers.lifecycle 启动后钩子点
下面是第8节课
[root@master yaml]# kubectl delete deploy nginx-deploy 删除Pod 名字是:nginx-deploy
pod控制器:
ReplicationContoller:
ReplicaSet:
Deployment:
DaemonSet:
JOB:
Cronjob:
SataefulSet:
[root@master yaml]# cat rs-demo.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx
namespace: default
sepc:
replicas: 2
selector:
matchLabels:
app: nginx
release: cannary
template:
metadata:
naame:
labels:
app: nginx
release: canary
environment: qa
spce:
contaioners:
name: nginx-container
image: nginx:latest
ports:
name: http
containerPort: 80
Service
工作模式:Userspace ,iptabes,ipvs
类型:
ExternalName ClusterIP,NodePort,LoadBalancer
vim svc_redis.yaml
apiVersion: v1
kind: Servcie
metadata:
name: redis
namespace: default
spec:
selector:
app: redis
role: logstor
clusterIP: 10.97.97.97
type: ClusterIP
ports:
port:6379
targetPort: 6379
创建服务:
kubectl apply -f svc_redis.yaml
查询信息
kuberl describe svc redis
资源记录s :
SVC_NAME.NS_NAME.DOMAIN.LTD.
svc.cluster.local.
****************************************************************************************************************
第二次笔记:
kubadm 部署K8S的工具
1.master: kubelet kubeadm ,docker
2.master: kubadm init
3.nodes: kubeadm join
注:1.各节点之间能通过主机名解析 及 能通过时间服务器同步时间
2.各节点的seliux关闭,firewalld关闭
一、配置yum仓库
docker:
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
kubernetes:
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name = CentOS 7 K8s
baseurl = https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck = 0
scp kubernetes.repo docker-ce.repo node01:/etc/yum.repos.d/
scp kubernetes.repo docker-ce.repo node02:/etc/yum.repos.d/
master:
yum install docker-ce kubelet kubeadm kubectl #kubectl -- 用于运行管理命令,节点可以也可以不用装
node:
yum install docker-ce kubelet kubeadm
systemctl enable kubelet
systemctl enable docker
-------------------------------EOF
下载相关镜像到本地:
镜像获取方法:
# 导出配置文件
kubeadm config print init-defaults --kubeconfig ClusterConfiguration > kubeadm.yml
# 国内不能访问 Google,修改为阿里云
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
# 修改版本号
kubernetesVersion: v1.15.0
# 查看所需镜像列表
kubeadm config images list --config kubeadm.yml
# 拉取镜像
kubeadm config images pull --config kubeadm.yml
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-apiserver:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-controller-manager:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-scheduler:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-proxy:v1.15.0
[config/images] Pulled registry.aliyuncs.com/google_containers/pause:3.1
[config/images] Pulled registry.aliyuncs.com/google_containers/etcd:3.3.10
[config/images] Pulled registry.aliyuncs.com/google_containers/coredns:1.3.1
重新打标签:
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.15.0 k8s.gcr.io/kube-apiserver:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.15.0 k8s.gcr.io/kube-controller-manager:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.15.0 k8s.gcr.io/kube-scheduler:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.15.0 k8s.gcr.io/kube-proxy:v1.15.0
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
[root@master yum.repos.d]# docker tag registry.aliyuncs.com/google_containers/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
master节点所镜像:
kang037/kube-proxy:v1.15.0
kang037/kube-apiserver:v1.15.0
kang037/kube-scheduler:v1.15.0
kang037/kube-controller-manager:v1.15.0
kang037/coredns:1.3.1
kang037/etcd:3.3.10
kang037/pause:3.1
node节点镜像
k8s.gcr.io/kube-proxy:v1.15.0
quay.io/coreos/flannel:v0.11.0-amd64
k8s.gcr.io/pause:3.1
以上镜像可通过阿里运下载后重新打标签即可
-----------------------------------------EOF
vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
kubeadm init --help #查看初始化帮助
kubeadm init --kubernetes-version=v1.xx.xx --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
--ignore-preflight-errors='Swap'
[root@master ~]#kubectl run nginx-deploy-01 --image=nginx:alpine --port=80 --replicas=1
[root@master ~]# kubectl get deployment --查看
[root@master ~]# kubectl get pods --查看运行的pod信息
NAME READY STATUS RESTARTS AGE
liveness-nginx-pod 0/1 CrashLoopBackOff 1457 56d
nginx-deploy-01-dfc49d8ff-9l8z2 1/1 Running 0 108s
[root@master ~]# kubectl get pods -o wide --显示更详细信息pod
[root@master ~]# kubectl delete pods nginx-deploy-69cb9d688c-l4cgs ---删除pod (nginx-deploy-69cb9d688c-l4cgs)
创建service
注:--默认集群内访问--type='': Type for this service: ClusterIP, NodePort, LoadBalancer, or ExternalName. Default is 'ClusterIP'.
[root@master ~]# kubectl expose deployment nginx-deploy-01 --port=80 --target-port=80 --protocol=TCP
[root@master ~]# kubectl get services|svc --查看service信息
[root@master ~]# kubectl get pods -n kube-system -o wide --查看kube-system名称空间运行的pod
[root@master ~]# kubectl describe svc nginx-deploy-01 --查看服务信息
[root@master ~]# kubectl get pod --show-labels -查看pod标签信息
NAME READY STATUS RESTARTS AGE LABELS
client 0/1 ImagePullBackOff 0 18m run=client
[root@master ~]# kubectl delete svc nginx-deploy-01 --删除服务
[root@master ~]# kubectl scale --replicas=5 deployment myapp --动态扩展myapp(pod名称)数量为5个pod
kubectl set image --更换版本命令
[root@master ~]# kubectl set image deployment myapp myapp=ikubernetes/myapp:v2 更新到v2版本
[root@master ~]# kubectl describe pods myapp-746644f8d6-22tbt --查看pod版本是否更新到v2
kubectl rollout undo --版本回滚
[root@master ~]# kubectl rollout undo deployment myapp ---默认回滚到上一次的版本
资源:对象
1.workload:Pod ,ReplicaSet ,Deployment,Job ....
2.服务发现及均衡:Service,ingress,....
3.配置与存储:Volume,CSI,....
4.集群级资源:NameSpace,Node,Role,ClusterRole,RoleBinding,ClusterRoleBinding
5.元数据型资源: HPA,PodTemplate,limitRange,...
以yaml格式输出到前台
[root@master ~]# kubectl get svc myapp01 -o yaml
[root@master ~]# kubectl get pods myapp-84cd4b7f95-5scc6 -o yaml
创建资源的方法:apiserver仅接收JSON格式的资源定义;
yaml格式提供配置清单,apiserver可自动将期转为json格式;
大部分资源的配置清单:
1.apiVersion :group/version #[root@master ~]# kubectl api-versions 查看
2.kind 资源类别
3.metadata: 元数据
name
namespace
labels
annotations
4.spce:用户期望的状态
containers <[object]>
-name <string>
image <string>
imagePullPolicy <string> (Always,Never,IfNotPresent)
Always: 总是拉取镜像
Never: 只使用本地镜像,从不拉取,即使本地没有
IfNotPresent: 本地有则使用本地镜像,不拉取 ,没有就拉取。
-ports <[object]> 对外显示IP端口
5.status:当前状态,current state,本字段由kubernetes集群维护
查看资源定义格式
[root@master ~]# kubectl explain pods (当前查看pod的定义格式)
根据yaml文件创建pod
1.vim pod-demo.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: default
labels:
app: web-nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx:latest
ports: #定义暴露端口
-name: http
comtainerPort: 80
-name: https
containerPort: 443
- name: myapp
image: ikubernetes/myapp:v1
2.[root@master ~]# kubectl create -f yaml/pod-demo.yaml #创建pod (里面有两个容器nginx和myapp)
3.[root@master ~]# kubectl get pods -w #查看pod状态
4.[root@master ~]# kubectl describe pods nginx(资料类型) #详细查看pod状态
[root@master ~]# kubectl delete pods nginx #删除
[root@master ~]# kubectl delete -f yaml/pod-demo.yaml #根据yaml文件删除
标签:key=value
key:字母或数字、下划线开头(63字符)不可以为空
value:字母或数字、下划线开头(63字符)可以为空,字母或数字开头和结尾
[root@master ~]# kubectl get pods -l app --show-labels #按标签过虑pod
[root@master ~]# kubectl label pods pod-demo release=canary #打标
[root@master ~]# kubectl label pods pod-demo release=stable --overwrite #修改
资源支持内嵌字段定义其使用的标签选择器:
matchLabels: 直接给定键值
matchExpressions: 基于给定的表达式来定义使用标签选择器 {key:"key",operator:"OPERATOR",values:[val1,val2,...]}
operator(操作符): In,NotIn :values字段值必须为非空列表;
Exists,NotExists :values字段值必须为空列表
nodeSelector <map[string]string> 节点标签选择器
annotations 资源注解,仅用于为对象提供"元数据"
pod生命周期
状态:Pending,Running,Failed,Succeeded,Unknown
restartPolicy: (重启策略)
Always,OnFailure,Never,Default to Always
三种探针 exec , tcpsocke ,httpget
[root@master ~]# cat yaml/livenessprobe.yaml #基于exec 探测
apiVersion: v1
kind: Pod
metadata:
name: liveness-pod
namespace: default
spec:
containers:
- name: liveness-exec-container
image: busybox:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 3600"]
livenessProbe:
exec:
command:
- "test"
- "-e"
- "/tmp/healthy"
initialDelaySeconds: 1
periodSeconds: 3
[root@master ~]# kubectl exec -it liveness-nginx-pod -- /bin/sh #手动连入容器内部操作
pod控制器:
ReplicationContoller:
ReplicaSet:
Deployment: 通过控制ReplicaSet来控制pod,关注群体,不用关注个体;无状态应用
[root@master ~]# kubectl explain deploy.spec
DaemonSet:实现一系统级的后台任务,运行一个Pod 在集群的每个节点(node)
JOB: 任务级别pod ,完成后自动删除pod
Cronjob:周期性运行pod,设置运行策略
StateFulSet:关注个体,有状态应用。
Deployment:
[root@master yaml]# cat deploy-demo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: nginx
release: canary
template:
metadata:
labels:
app: nginx
release: canary
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- name: http
containerPort: 80
[root@master yaml]# kubectl apply -f deploy-demo.yaml
[root@master yaml]# kubectl patch deployment nginx-deploy -p '{"spec":{"replicas":5}}' #打补丁方式更新Deployment创建的pod,更改副本为5个
DaemonSet:
[root@master yaml]# cat daemonset-demo.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-ds
namespace: default
spec:
selector:
matchLabels:
app: filebeat
release: stable
template:
metadata:
labels:
app: filebeat
release: stable
spec:
containers:
- name: filebeat
image: ikubernetes/filebeat:5.6.5-alpine
env:
- name: REDIS_HOST
value: redis.default.svc.cluster.local
- name: REDIS_LOG_LEVEL
value: info
[root@master yaml]# kubectl apply -f daemonset-demo.yaml
Service:
工作模式:Userspace,iptables,ipvs
类型: ExternalName, ClusterIP, NodePort, LoadBalancer
[root@master ~]# kubectl explain svc
Ingress Controller : #用于七层控制
存储:脱离节点存在的共享存储设备
SAN: ISCSI
NAS:nfs,cifs
分布式存储:glusterfs ,rbd,ccphfs
云存储:EBS,Azure Disk
[root@master ~]# kubect explain pod.spec.volume #查看支持的存储