注意把10.170.208.111 替换成自己linux虚拟机的ip地址
1、安装k8s——具体安装过程ubuntu和centos及其他版本略有差异,根据网上资料自己安装
# kubeadm init \
--apiserver-advertise-address=10.170.208.111 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version=v1.19.4 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--token-ttl=0
安装方式建议实用kubeadm安装方式
2、污点化主节点,这样你的节点才可以部署应用 【我自己单节点测试,三主三从以上的地主人家不用这么折腾】
kubectl taint nodes --all node-role.kubernetes.io/master-
3、安装网络
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
多网卡服务器需要指定网卡
vim kube-flannel.yml
kubectl apply -f kube-flannel.yml
查找问题 journalctl -f -u kubelet.service
4、安装负载均衡
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.6/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.6/manifests/metallb.yaml
# On first install only
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
cat <<EOF>metallb.cfg
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 10.170.208.10-10.170.208.15
EOF
10.170.208.10-10.170.208.15 是负载均衡使用的ip范围
kubectl apply -f metallb.cfg
4、部署Dashboard UI (v2.2.0)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
vim recommended.yaml
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30000
selector:
k8s-app: kubernetes-dashboard
kubectl apply -f recommended.yaml
cat <<EOF>admin-user.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
EOF
kubectl apply -f admin-user.yaml
serviceaccount/admin-user created
Creating a ClusterRoleBinding
cat <<EOF>ClusterRoleBinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
EOF
kubectl apply -f ClusterRoleBinding.yaml
使用token进行登录,执行下面命令获取token
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
kubectl create clusterrolebinding serviceaccount-cluster-admin --clusterrole=cluster-admin --group=system:serviceaccount
5、安装istio
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.10.0
export PATH=$PWD/bin:$PATH
istioctl install --set profile=demo -y
kubectl label namespace default istio-injection=enabled
6、安装helm
wget https://get.helm.sh/helm-v3.6.1-linux-amd64.tar.gz
tar -zxvf helm-v3.6.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
7、安装nfs和nfs-client实现动态分配pv pvc
共享端安装nfs-server,k8s所在主机安装nfs客户端【具体根据linux版本安装对应包】
以ubuntu为例:
apt-get install nfs-kernel-server
vim /etc/exports
/data/k8s *(rw,sync,no_root_squash)
手动
mount -t nfs -o nolock -o tcp 10.170.208.111:/data/k8s /nfs
自动
vim /etc/fstab
# nfs volumes
10.170.208.111:/data/k8s /nfs nfs defaults 0 0
helm search repo nfs-client-provisioner
helm install aliyuncs/nfs-client-provisioner --name nfs-storageclass --set nfs.server=10.170.208.111 --set nfs.path=/data/k8s
helm install stable/nfs-client-provisioner --name nfs-storageclass --set nfs.server=10.170.208.111 --set nfs.path=/data/k8s
helm pull stable/nfs-client-provisioner --untar
cd nfs-client-provisioner/
vim values.yaml
values.yaml
...
nfs:
server: 10.170.208.111
path: /data/k8s
mountOptions:
...
helm install nfs -f values.yaml .
8、kafka 【service.type 自己设置自己选】
helm pull aliyuncs/kafka
tar -zxvf kafka-7.2.2.tgz
cd kafka
helm install kafka . -f ./values.yaml --set service.type=NodePort
9、postgresql-ha
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install bibt bitnami/postgresql-ha
export POSTGRES_PASSWORD=$(kubectl get secret --namespace default bibt-postgresql-ha-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
export | grep POSTGRES_PASSWORD
export REPMGR_PASSWORD=$(kubectl get secret --namespace default bibt-postgresql-ha-postgresql -o jsonpath="{.data.repmgr-password}" | base64 --decode)
export | grep REPMGR_PASSWORD
10、redis
helm install redis-service bitnami/redis-cluster
export REDIS_PASSWORD=$(kubectl get secret --namespace "default" redis-service-redis-cluster -o jsonpath="{.data.redis-password}" | base64 --decode)
export | grep REDIS_PASSWORD
11、mongodb
helm install mongodb bitnami/mongodb
export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
export | grep MONGODB_ROOT_PASSWORD
12、mqtt
helm install mqtt emqx/emqx --set service.type=LoadBalancer
export EMQX_ROOT_PASSWORD=$(kubectl get secret --namespace default mqtt -o jsonpath="{.data.emqx-root-password}" | base64 --decode)
export | grep EMQX_ROOT_PASSWORD
13、ElasticSearch kibana apm-server filebeat
ElasticSearch 的 Helm Chart 模板是 ES 官方 Github 获取的,它的 Github 地址为 https://github.com/elastic/helm-charts。
# Helm 增加 Elastic 仓库
helm repo add elastic https://helm.elastic.co
# 安装 ElasticSearch Master 节点
helm install elasticsearch --set antiAffinity=soft elastic/elasticsearch
helm install kibana elastic/kibana
helm install apm-server elastic/apm-server
wget https://github.com/elastic/helm-charts/archive/refs/tags/v7.13.2.tar.gz
tar -zxvf v7.13.2.tar.gz
cd helm-charts-7.13.2/filebeat/examples/deployment
make install
helm upgrade --wait --timeout=900s --install --values values.yaml helm-filebeat-deployment ../../