版本
注意k8s与docker的版本适配。(2018-11-15的最新版:k8s=v1.12.2不支持docker=18.09.1)
docker
https://docs.docker-cn.com/engine/installation/linux/docker-ce/ubuntu/
curl -fs https://raw.githubusercontent.com/archongum/kubernetes-files/master/gpg | sudo apt-key add -
echo "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable" >> /etc/apt/sources.list
# 查看版本
# apt-cache madison docker-ce
apt update
apt install docker-ce=18.06.1~ce~3-0~ubuntu
kubernetes
kubeadm kubectl kubelet
CentOS
https://www.kubernetes.org.cn/4619.html
ubuntu
https://linuxconfig.org/how-to-install-kubernetes-on-ubuntu-18-04-bionic-beaver-linux
https://www.coder4.com/archives/6107
curl -fs https://raw.githubusercontent.com/archongum/kubernetes-files/master/apt-key.gpg | apt-key add -
# 目前只有xenial(2018-11-15)
echo "deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt update
apt install kubelet kubeadm kubectl
其他系统操作
关swap(选)
swapoff -a
vim /etc/fstab
注释swap加载
初始化k8s
#
# --ignore-preflight-errors=Swap
kubeadm init \
--kubernetes-version=v1.12.2 \
--pod-network-cidr=10.244.0.0/16 \
--apiserver-advertise-address=192.168.4.41
需要科学上网下载docker镜像,根据镜像的版本去dockerhub找其他人的镜像,然后tag
https://hub.docker.com/u/mirrorgooglecontainers/
整理的k8s=v1.12.2的替代docker
# 版本信息
K8S_VERSION=v1.12.2
ETCD_VERSION=3.2.24
DNS_VERSION=1.2.2
PAUSE_VERSION=3.1
FLANNEL_VERSION=v0.10.0-amd64
DASHBOARD_VERSION=v1.10.0
# 基本组件
docker pull mirrorgooglecontainers/kube-apiserver:$K8S_VERSION
docker pull mirrorgooglecontainers/kube-controller-manager:$K8S_VERSION
docker pull mirrorgooglecontainers/kube-scheduler:$K8S_VERSION
docker pull mirrorgooglecontainers/kube-proxy:$K8S_VERSION
docker pull mirrorgooglecontainers/etcd:$ETCD_VERSION
docker pull mirrorgooglecontainers/pause:$PAUSE_VERSION
## 网络
docker pull coredns/coredns:$DNS_VERSION
docker pull quay.io/coreos/flannel:$FLANNEL_VERSION
## 前端
docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:$DASHBOARD_VERSION
# 修改tag
docker tag mirrorgooglecontainers/kube-apiserver:$K8S_VERSION k8s.gcr.io/kube-apiserver:$K8S_VERSION
docker tag mirrorgooglecontainers/kube-controller-manager:$K8S_VERSION k8s.gcr.io/kube-controller-manager:$K8S_VERSION
docker tag mirrorgooglecontainers/kube-scheduler:$K8S_VERSION k8s.gcr.io/kube-scheduler:$K8S_VERSION
docker tag mirrorgooglecontainers/kube-proxy:$K8S_VERSION k8s.gcr.io/kube-proxy:$K8S_VERSION
docker tag mirrorgooglecontainers/etcd:$ETCD_VERSION k8s.gcr.io/etcd:$ETCD_VERSION
docker tag mirrorgooglecontainers/pause:$PAUSE_VERSION k8s.gcr.io/pause:$PAUSE_VERSION
## 网络
docker tag coredns/coredns:$DNS_VERSION k8s.gcr.io/coredns:$DNS_VERSION
## 前端
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:$DASHBOARD_VERSION k8s.gcr.io/kubernetes-dashboard:$DASHBOARD_VERSION
# 删除images
docker rmi mirrorgooglecontainers/kube-apiserver:$K8S_VERSION
docker rmi mirrorgooglecontainers/kube-controller-manager:$K8S_VERSION
docker rmi mirrorgooglecontainers/kube-scheduler:$K8S_VERSION
docker rmi mirrorgooglecontainers/kube-proxy:$K8S_VERSION
docker rmi mirrorgooglecontainers/etcd:$ETCD_VERSION
docker rmi mirrorgooglecontainers/pause:$PAUSE_VERSION
## 网络
docker rmi coredns/coredns:$DNS_VERSION
## 前端
docker rmi mirrorgooglecontainers/kubernetes-dashboard-amd64:$DASHBOARD_VERSION
初始化设置
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
网卡flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Maven docker plugin
https://my.oschina.net/u/3971841/blog/2056302
plugin
PS: 可以改images的名字
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<configuration>
<dockerHost>http://192.168.4.41:2375</dockerHost>
<imageName>${docker.repository.prefix}/${project.artifactId}</imageName>
<imageTags>
<imageTag>${version}</imageTag>
</imageTags>
<baseImage>openjdk:8-jre-alpine</baseImage>
<entryPoint>["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<targetPath>/</targetPath>
<includes>
<include>${project.build.finalName}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</plugin>
build
mvn clean package -Dmaven.test.skip=true
mvn docker:build
docker run(非k8s步骤)
docker run \
-it \
-e "SPRING_PROFILES_ACTIVE=dev" \
model-dealer:latest \
sh
k8s使用本地image部署
本地docker register
https://blog.csdn.net/wzp1986/article/details/55829974
docker run \
-d \
-p 5000:5000 \
--restart=always \
--name="localdocker" \
-v /data/localdocker:/registry \
-e REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/registry \
registry