准备工作
ntpdate time.windows.com
swapoff -a
安装docker-ce、kubelet等
启动docker
systemctl start docker
启动kubelet
systemctl enable kubelet
初始化kube
kubeadm init
--apiserver-advertise-address=192.168.5.221
--image-repository registry.aliyuncs.com/google_containers
--kubernetes-version v1.17.0
--service-cidr=10.96.0.0/12
--pod-network-cidr=10.244.0.0/16
unset DOCKER_HOST
检查是否好了
kubectl get pods -n kube-system
kubectl get node
安装flannel插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yaml
忘记秘钥或者重新连接
kubeadm token create --print-join-command
加入node
kubeadm join 192.168.5.221:6443 --token 5citnv.qwhlzu7ezy3fajke --discovery-token-ca-cert-hash sha256:dc3bd880169f5856a8baeeb636d02d7e64a857cc4ff1594559fe7c080b535b79
加入hosts
199.232.28.133 raw.githubusercontent.com
安装dashboard
kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
kubectl apply -f dashboard.yaml
kubectl get pods -n kubernetes-dashboard
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
运行下面的 复制token登录
kubectl describe secrets -n kube-system 1}')
eyJhbGciOiJSUzI1NiIsImtpZCI6IkYxWXRzbW44UFBLZFI0ZzlyRnJpZ0FENWZpOEd5NzlLZE9RdWRDVW9lWUkifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4td2twc2ciLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZTBmODA1YjgtMWU0NS00YjA3LWJmOTctNzI0MTViODY1ZWUzIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.My1Y5IM91EYhNV9O7Aw4zdB4C9QW_itr_jGEtys-AqEBWRRByqrentrtW44WSMx85UOW8iSGtpOsomx2LluecI-6gExY6Z9ZIce9iy7M1Pv5rEyhS3OmtDZNbtU4FKSCgEA-cTiegUzNIP3sqD1fZFwma_Hq5CkUfj6LoRD79u2wGAlu4uWEBjXy08N4tkIf6z5ySsM7-BVP6Waj0pYLHVwc86QhjZ7qeVVaczmJL81ZZjq--ptTS-oWatDGz8MR5K5AiUIzoZUMyz2xy12N1VN7KmZnvbVJ-xbjYrmH67xNKB6_9seSaKs_tf9kHWjNnHF0DHcmPl74SEc1rrLkuQ
创建pod 测试 集群
$ kubectl create deployment nginx --image=nginx
$ kubectl expose deployment nginx --port=80 --type=NodePort
$ kubectl get pod,svc
docker save -o flannel.tar lizhenliang/flannel:v0.11.0-amd64
部署镜像到k8s
创建镜像iamge 在镜像java 程序 的 根目录
docker build -t lizhenliang/java-demo .
一、通过dockerhub方法: 1、登录镜像仓库
docker login
一、通过dockerhub方法: 2 推iamge 到 仓库
docker push lizhenliang/java-demo
一、通过dockerhub方法: 3 拉镜像到node节点
docker pull lizhenliang/java-demo
二、通过本地仓库方法: 1 导出镜像到 本地
docker save -o java-demo.tar lizhenliang/java-demo
二、通过本地仓库方法: 2 scp 复制到node节点上, 导入镜像,无需通过仓库
docker load -i java-demo.tar
部署docker ,先生成镜像yaml 模板
kubectl create deployment java-demo --image=lizhenliang/java-demo --dry-run -o yaml > deployjava.yaml
编辑如下内容
image: 改为本地地址,默认是docker官方hub地址
应用yaml
kubectl apply -f deployjava.yaml
暴露服务,先生成yaml
kubectl expose deployment java-demo --port=80 --target-port=8080 --type=NodePort -o yaml --dry-run > svc.yaml
暴露服务,应用yaml
kubectl apply -f svc.yaml
删除pods
kubectl get pod
kubectl delete java-demo-8548998c57-g2klp
删除已经部署的 pods 方法,要删除deployment ,光删除pod不行
kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
java-demo 1/1 1 1 4d14h
nginx 1/1 1 1 5d15h
kubectl delete java-demo
kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 5d15h