接上一篇文章飒硅,使用上一篇文章搭建的實驗環(huán)境進行操作,一主一從
1.k8s簡介
1.1集群介紹
K8s是一個開源的容器框架浸须。也可以作為微服務(wù)治理框架移怯,k8s提供了基本的服務(wù)發(fā)現(xiàn)、服務(wù)治理和橙、負載均衡功能仔燕。
K8s集群由master節(jié)點和node節(jié)點組成造垛,集群至少需要一個master節(jié)點、一個node節(jié)點
Master節(jié)點
Master節(jié)點指的是集群控制節(jié)點晰搀,管理和控制整個集群五辽,基本上k8s的所有控制命令都發(fā)給它,它負責(zé)具體的執(zhí)行過程外恕。
Node節(jié)點
除了master以外的節(jié)點被稱為Node或者Worker節(jié)點杆逗,可以在master中使用命令 kubectl get nodes查看集群中的node節(jié)點。每個Node都會被Master分配一些工作負載(Docker容器)吁讨,當(dāng)某個Node宕機時髓迎,該節(jié)點上的工作負載就會被Master自動轉(zhuǎn)移到其它節(jié)點上。
1.2K8s服務(wù)模型
在k8s中建丧,最小的單位是一個docker鏡像(container)排龄,一個和多個docker封裝在一個pod當(dāng)中。在k8s中,k8s調(diào)度的最小單位就是一個pod翎朱。K8s中提供了Service組件綁定pod橄维,可以由Service提供pod的負載均衡,Deployment組件進行pod的部署拴曲。
Ingress組件提供負載均衡功能争舞,通過名稱標(biāo)識綁定Service。在沒有負載均衡的情況下澈灼。Service竞川、pod等也能單獨暴露外網(wǎng)端口,后續(xù)章節(jié)會詳細描述叁熔,但一般使用ingress進行外部負載委乌。Service的負載只在4層有負載,只能到IP層面荣回。Ingress遭贸、deployment、service心软、pod壕吹、image的關(guān)系如下圖:
2.k8s集群搭建
使用root用戶
2.1安裝docker
執(zhí)行腳本:
#!/bin/bash
apt-get update
apt-get install -y apt-transport-https ca-certificates
curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io
2.2安裝Kubernetes(k8s)
執(zhí)行腳本:
#!/bin/bash
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
apt-get update
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get install -y kubelet kubeadm kubectl --allow-unauthenticated
2.3關(guān)閉swap
暫時關(guān)閉?
直接使用命令sudo swapoff -a,但是重啟之后會失效删铃。會導(dǎo)致k8s無法正常運行耳贬。
永久關(guān)閉
建議一勞永逸,sudo vim /etc/fstab將有swap.img那行注釋掉泳姐,保存即可效拭。
關(guān)閉swap可以提高性能。但對內(nèi)存要求更高。
2.4初始化master節(jié)點
ssh登錄master的系統(tǒng)
設(shè)置主機名缎患,名字自己起即可慕的,用于標(biāo)識該節(jié)點
hostnamectl set-hostname master-node
初始化集群
kubeadm init --pod-network-cidr=10.244.0.0/16
這個命令執(zhí)行完成之后,會打印一個有kubeadm join的命令挤渔,需要保存下來肮街。
樣式:
kubeadm join 你的IP地址:6443 --token 你的TOKEN --discovery-token-ca-cert-hash sha256:你的CA證書哈希
這個命令用于其他節(jié)點加入到集群中,而且token是有時效性的判导,過期時間一般是86400000毫秒嫉父。
如果失效,需要重新生成眼刃,或者使用以下方式獲热葡健:
token:通過命令Kubeadm token list找回
ca-cert:執(zhí)行命令openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'找回
2.5安裝網(wǎng)絡(luò)通信插件
網(wǎng)絡(luò)插件也是一個服務(wù),安裝網(wǎng)絡(luò)服務(wù)才能使節(jié)點從NotReady變成Ready狀態(tài)擂红,使用kubectl apply部署服務(wù):
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
由于網(wǎng)絡(luò)原因仪际,一般這個yml文件無法下載,本文提供一個昵骤,kube-flannel.yml:
---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
? name: psp.flannel.unprivileged
? annotations:
? ? seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/default
? ? seccomp.security.alpha.kubernetes.io/defaultProfileName: docker/default
? ? apparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/default
? ? apparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default
spec:
? privileged: false
? volumes:
? ? - configMap
? ? - secret
? ? - emptyDir
? ? - hostPath
? allowedHostPaths:
? ? - pathPrefix: "/etc/cni/net.d"
? ? - pathPrefix: "/etc/kube-flannel"
? ? - pathPrefix: "/run/flannel"
? readOnlyRootFilesystem: false
? # Users and groups
? runAsUser:
? ? rule: RunAsAny
? supplementalGroups:
? ? rule: RunAsAny
? fsGroup:
? ? rule: RunAsAny
? # Privilege Escalation
? allowPrivilegeEscalation: false
? defaultAllowPrivilegeEscalation: false
? # Capabilities
? allowedCapabilities: ['NET_ADMIN']
? defaultAddCapabilities: []
? requiredDropCapabilities: []
? # Host namespaces
? hostPID: false
? hostIPC: false
? hostNetwork: true
? hostPorts:
? - min: 0
? ? max: 65535
? # SELinux
? seLinux:
? ? # SELinux is unused in CaaSP
? ? rule: 'RunAsAny'
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
? name: flannel
rules:
? - apiGroups: ['extensions']
? ? resources: ['podsecuritypolicies']
? ? verbs: ['use']
? ? resourceNames: ['psp.flannel.unprivileged']
? - apiGroups:
? ? ? - ""
? ? resources:
? ? ? - pods
? ? verbs:
? ? ? - get
? - apiGroups:
? ? ? - ""
? ? resources:
? ? ? - nodes
? ? verbs:
? ? ? - list
? ? ? - watch
? - apiGroups:
? ? ? - ""
? ? resources:
? ? ? - nodes/status
? ? verbs:
? ? ? - patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
? name: flannel
roleRef:
? apiGroup: rbac.authorization.k8s.io
? kind: ClusterRole
? name: flannel
subjects:
- kind: ServiceAccount
? name: flannel
? namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
? name: flannel
? namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
? name: kube-flannel-cfg
? namespace: kube-system
? labels:
? ? tier: node
? ? app: flannel
data:
? cni-conf.json: |
? ? {
? ? ? "name": "cbr0",
? ? ? "cniVersion": "0.3.1",
? ? ? "plugins": [
? ? ? ? {
? ? ? ? ? "type": "flannel",
? ? ? ? ? "delegate": {
? ? ? ? ? ? "hairpinMode": true,
? ? ? ? ? ? "isDefaultGateway": true
? ? ? ? ? }
? ? ? ? },
? ? ? ? {
? ? ? ? ? "type": "portmap",
? ? ? ? ? "capabilities": {
? ? ? ? ? ? "portMappings": true
? ? ? ? ? }
? ? ? ? }
? ? ? ]
? ? }
? net-conf.json: |
? ? {
? ? ? "Network": "10.244.0.0/16",
? ? ? "Backend": {
? ? ? ? "Type": "vxlan"
? ? ? }
? ? }
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
? name: kube-flannel-ds-amd64
? namespace: kube-system
? labels:
? ? tier: node
? ? app: flannel
spec:
? selector:
? ? matchLabels:
? ? ? app: flannel
? template:
? ? metadata:
? ? ? labels:
? ? ? ? tier: node
? ? ? ? app: flannel
? ? spec:
? ? ? affinity:
? ? ? ? nodeAffinity:
? ? ? ? ? requiredDuringSchedulingIgnoredDuringExecution:
? ? ? ? ? ? nodeSelectorTerms:
? ? ? ? ? ? ? - matchExpressions:
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/os
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - linux
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/arch
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - amd64
? ? ? hostNetwork: true
? ? ? tolerations:
? ? ? - operator: Exists
? ? ? ? effect: NoSchedule
? ? ? serviceAccountName: flannel
? ? ? initContainers:
? ? ? - name: install-cni
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-amd64
? ? ? ? command:
? ? ? ? - cp
? ? ? ? args:
? ? ? ? - -f
? ? ? ? - /etc/kube-flannel/cni-conf.json
? ? ? ? - /etc/cni/net.d/10-flannel.conflist
? ? ? ? volumeMounts:
? ? ? ? - name: cni
? ? ? ? ? mountPath: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? containers:
? ? ? - name: kube-flannel
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-amd64
? ? ? ? command:
? ? ? ? - /opt/bin/flanneld
? ? ? ? args:
? ? ? ? - --ip-masq
? ? ? ? - --kube-subnet-mgr
? ? ? ? resources:
? ? ? ? ? requests:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? ? limits:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? securityContext:
? ? ? ? ? privileged: false
? ? ? ? ? capabilities:
? ? ? ? ? ? add: ["NET_ADMIN"]
? ? ? ? env:
? ? ? ? - name: POD_NAME
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.name
? ? ? ? - name: POD_NAMESPACE
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.namespace
? ? ? ? volumeMounts:
? ? ? ? - name: run
? ? ? ? ? mountPath: /run/flannel
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? volumes:
? ? ? ? - name: run
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /run/flannel
? ? ? ? - name: cni
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? configMap:
? ? ? ? ? ? name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
? name: kube-flannel-ds-arm64
? namespace: kube-system
? labels:
? ? tier: node
? ? app: flannel
spec:
? selector:
? ? matchLabels:
? ? ? app: flannel
? template:
? ? metadata:
? ? ? labels:
? ? ? ? tier: node
? ? ? ? app: flannel
? ? spec:
? ? ? affinity:
? ? ? ? nodeAffinity:
? ? ? ? ? requiredDuringSchedulingIgnoredDuringExecution:
? ? ? ? ? ? nodeSelectorTerms:
? ? ? ? ? ? ? - matchExpressions:
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/os
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - linux
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/arch
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - arm64
? ? ? hostNetwork: true
? ? ? tolerations:
? ? ? - operator: Exists
? ? ? ? effect: NoSchedule
? ? ? serviceAccountName: flannel
? ? ? initContainers:
? ? ? - name: install-cni
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-arm64
? ? ? ? command:
? ? ? ? - cp
? ? ? ? args:
? ? ? ? - -f
? ? ? ? - /etc/kube-flannel/cni-conf.json
? ? ? ? - /etc/cni/net.d/10-flannel.conflist
? ? ? ? volumeMounts:
? ? ? ? - name: cni
? ? ? ? ? mountPath: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? containers:
? ? ? - name: kube-flannel
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-arm64
? ? ? ? command:
? ? ? ? - /opt/bin/flanneld
? ? ? ? args:
? ? ? ? - --ip-masq
? ? ? ? - --kube-subnet-mgr
? ? ? ? resources:
? ? ? ? ? requests:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? ? limits:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? securityContext:
? ? ? ? ? privileged: false
? ? ? ? ? capabilities:
? ? ? ? ? ? add: ["NET_ADMIN"]
? ? ? ? env:
? ? ? ? - name: POD_NAME
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.name
? ? ? ? - name: POD_NAMESPACE
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.namespace
? ? ? ? volumeMounts:
? ? ? ? - name: run
? ? ? ? ? mountPath: /run/flannel
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? volumes:
? ? ? ? - name: run
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /run/flannel
? ? ? ? - name: cni
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? configMap:
? ? ? ? ? ? name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
? name: kube-flannel-ds-arm
? namespace: kube-system
? labels:
? ? tier: node
? ? app: flannel
spec:
? selector:
? ? matchLabels:
? ? ? app: flannel
? template:
? ? metadata:
? ? ? labels:
? ? ? ? tier: node
? ? ? ? app: flannel
? ? spec:
? ? ? affinity:
? ? ? ? nodeAffinity:
? ? ? ? ? requiredDuringSchedulingIgnoredDuringExecution:
? ? ? ? ? ? nodeSelectorTerms:
? ? ? ? ? ? ? - matchExpressions:
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/os
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - linux
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/arch
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - arm
? ? ? hostNetwork: true
? ? ? tolerations:
? ? ? - operator: Exists
? ? ? ? effect: NoSchedule
? ? ? serviceAccountName: flannel
? ? ? initContainers:
? ? ? - name: install-cni
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-arm
? ? ? ? command:
? ? ? ? - cp
? ? ? ? args:
? ? ? ? - -f
? ? ? ? - /etc/kube-flannel/cni-conf.json
? ? ? ? - /etc/cni/net.d/10-flannel.conflist
? ? ? ? volumeMounts:
? ? ? ? - name: cni
? ? ? ? ? mountPath: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? containers:
? ? ? - name: kube-flannel
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-arm
? ? ? ? command:
? ? ? ? - /opt/bin/flanneld
? ? ? ? args:
? ? ? ? - --ip-masq
? ? ? ? - --kube-subnet-mgr
? ? ? ? resources:
? ? ? ? ? requests:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? ? limits:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? securityContext:
? ? ? ? ? privileged: false
? ? ? ? ? capabilities:
? ? ? ? ? ? add: ["NET_ADMIN"]
? ? ? ? env:
? ? ? ? - name: POD_NAME
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.name
? ? ? ? - name: POD_NAMESPACE
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.namespace
? ? ? ? volumeMounts:
? ? ? ? - name: run
? ? ? ? ? mountPath: /run/flannel
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? volumes:
? ? ? ? - name: run
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /run/flannel
? ? ? ? - name: cni
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? configMap:
? ? ? ? ? ? name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
? name: kube-flannel-ds-ppc64le
? namespace: kube-system
? labels:
? ? tier: node
? ? app: flannel
spec:
? selector:
? ? matchLabels:
? ? ? app: flannel
? template:
? ? metadata:
? ? ? labels:
? ? ? ? tier: node
? ? ? ? app: flannel
? ? spec:
? ? ? affinity:
? ? ? ? nodeAffinity:
? ? ? ? ? requiredDuringSchedulingIgnoredDuringExecution:
? ? ? ? ? ? nodeSelectorTerms:
? ? ? ? ? ? ? - matchExpressions:
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/os
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - linux
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/arch
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - ppc64le
? ? ? hostNetwork: true
? ? ? tolerations:
? ? ? - operator: Exists
? ? ? ? effect: NoSchedule
? ? ? serviceAccountName: flannel
? ? ? initContainers:
? ? ? - name: install-cni
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-ppc64le
? ? ? ? command:
? ? ? ? - cp
? ? ? ? args:
? ? ? ? - -f
? ? ? ? - /etc/kube-flannel/cni-conf.json
? ? ? ? - /etc/cni/net.d/10-flannel.conflist
? ? ? ? volumeMounts:
? ? ? ? - name: cni
? ? ? ? ? mountPath: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? containers:
? ? ? - name: kube-flannel
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-ppc64le
? ? ? ? command:
? ? ? ? - /opt/bin/flanneld
? ? ? ? args:
? ? ? ? - --ip-masq
? ? ? ? - --kube-subnet-mgr
? ? ? ? resources:
? ? ? ? ? requests:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? ? limits:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? securityContext:
? ? ? ? ? privileged: false
? ? ? ? ? capabilities:
? ? ? ? ? ? add: ["NET_ADMIN"]
? ? ? ? env:
? ? ? ? - name: POD_NAME
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.name
? ? ? ? - name: POD_NAMESPACE
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.namespace
? ? ? ? volumeMounts:
? ? ? ? - name: run
? ? ? ? ? mountPath: /run/flannel
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? volumes:
? ? ? ? - name: run
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /run/flannel
? ? ? ? - name: cni
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? configMap:
? ? ? ? ? ? name: kube-flannel-cfg
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
? name: kube-flannel-ds-s390x
? namespace: kube-system
? labels:
? ? tier: node
? ? app: flannel
spec:
? selector:
? ? matchLabels:
? ? ? app: flannel
? template:
? ? metadata:
? ? ? labels:
? ? ? ? tier: node
? ? ? ? app: flannel
? ? spec:
? ? ? affinity:
? ? ? ? nodeAffinity:
? ? ? ? ? requiredDuringSchedulingIgnoredDuringExecution:
? ? ? ? ? ? nodeSelectorTerms:
? ? ? ? ? ? ? - matchExpressions:
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/os
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - linux
? ? ? ? ? ? ? ? ? - key: beta.kubernetes.io/arch
? ? ? ? ? ? ? ? ? ? operator: In
? ? ? ? ? ? ? ? ? ? values:
? ? ? ? ? ? ? ? ? ? ? - s390x
? ? ? hostNetwork: true
? ? ? tolerations:
? ? ? - operator: Exists
? ? ? ? effect: NoSchedule
? ? ? serviceAccountName: flannel
? ? ? initContainers:
? ? ? - name: install-cni
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-s390x
? ? ? ? command:
? ? ? ? - cp
? ? ? ? args:
? ? ? ? - -f
? ? ? ? - /etc/kube-flannel/cni-conf.json
? ? ? ? - /etc/cni/net.d/10-flannel.conflist
? ? ? ? volumeMounts:
? ? ? ? - name: cni
? ? ? ? ? mountPath: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? containers:
? ? ? - name: kube-flannel
? ? ? ? image: quay.io/coreos/flannel:v0.11.0-s390x
? ? ? ? command:
? ? ? ? - /opt/bin/flanneld
? ? ? ? args:
? ? ? ? - --ip-masq
? ? ? ? - --kube-subnet-mgr
? ? ? ? resources:
? ? ? ? ? requests:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? ? limits:
? ? ? ? ? ? cpu: "100m"
? ? ? ? ? ? memory: "50Mi"
? ? ? ? securityContext:
? ? ? ? ? privileged: false
? ? ? ? ? capabilities:
? ? ? ? ? ? add: ["NET_ADMIN"]
? ? ? ? env:
? ? ? ? - name: POD_NAME
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.name
? ? ? ? - name: POD_NAMESPACE
? ? ? ? ? valueFrom:
? ? ? ? ? ? fieldRef:
? ? ? ? ? ? ? fieldPath: metadata.namespace
? ? ? ? volumeMounts:
? ? ? ? - name: run
? ? ? ? ? mountPath: /run/flannel
? ? ? ? - name: flannel-cfg
? ? ? ? ? mountPath: /etc/kube-flannel/
? ? ? volumes:
? ? ? ? - name: run
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /run/flannel
? ? ? ? - name: cni
? ? ? ? ? hostPath:
? ? ? ? ? ? path: /etc/cni/net.d
? ? ? ? - name: flannel-cfg
? ? ? ? ? configMap:
? ? ? ? ? ? name: kube-flannel-cfg
2.6slave節(jié)點加入集群
slave節(jié)點也需要執(zhí)行2.1树碱、2.2、2.3变秦、2.5節(jié)內(nèi)容進行k8s+docker基礎(chǔ)環(huán)境搭建成榜。然后執(zhí)行以下步驟
設(shè)置node節(jié)點主機名
hostnamectl set-hostname slave-node
加入集群
執(zhí)行上一章節(jié)生成的kubeadm join命令即可
執(zhí)行完畢后,可通過kubectl get nodes命令查看節(jié)點情況:
2.7普通用戶
為了普通用戶也能在節(jié)點上使用k8s命令蹦玫,做以下操作赎婚,非必須操作:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
綜上所述,基礎(chǔ)的k8s集群搭建完畢樱溉,搭建過程中可能會遇到一些問題惑淳,下一篇文章總結(jié)一下大家過程中遇到的一些問題以及解決方法。