省略k8s与docker的安装过程
主要碰到问题如下:
使用k8拉去本地镜像的时候发现拉不下来报错
![image.png](https://upload-images.jianshu.io/upload_images/13612885-1370e4a3314043ae.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
于是改变策略,先与本地建立一个私人仓库
docker pull registry
mkdir -p /opt/data/registry //创建目录
sudo docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry --name private_registry registry //启动容器
sudo service docker restart //重启容器
sudo docker start private_registry //重启registry服务
sudo docker tag mytest:latest 192.168.147.129:5000/mytest(mytest为我打包的一个http服务)
sudo docker push 192.168.147.129:5000/mytest(此处可能报错需要设置/etc/docker/daemon.json)
设置如下:
{
"registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"],
"insecure-registries":["XX.XX.XX.XX:5000"]
}
设置完重新push即可
k8s部署yaml文件:
apiVersion: v1
kind: ReplicationController
metadata:
name: mytest
spec:
replicas: 1
selector:
app: mytest
template:
metadata:
labels:
app: mytest
spec:
containers:
- name: mytest
image: xx,xx,xx,xx:5000/mytest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8550
然后创建此pod
kubectl create -f demo-rc.yaml
但这样外包还是无法访问该pod,需要在创建一个serivies
yaml文件如下:
apiVersion: v1
kind: Service
metadata:
name: mytest
spec:
type: NodePort
ports:
- port: 8550
targetPort: 8550
nodePort: 30001
selector:
app: mytest
kubectl create -f demo-svc.yaml