K8snode
CI :持續集成
CD :持續交付 D --Delivery
CD :持續部署 D --Deploymentlinux
Kubernetes Cluster:nginx
Masters: (3-host 作高可用)
APIServer ,Scheduler ,Controller-Mangergit
Node:
Kubelet,docker,kube-proxygithub
Pod,Label,Label Selectorweb
Label:key=valueredis
1.同一個Pod內的多個容器間通訊:loopback
2.各Pod之間的通訊:
3.Pod與Service之間的通訊:docker
CNI:
flannet:網絡配置
calico:網絡配置,網絡策略
canel:上兩個的結合json
kubeadm 集羣部署軟件
每一個節點都要安裝:kubelet,dockervim
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 對主機所作的任何更改
三、用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關閉
1、配置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 #查看支持的存儲