1.Deployment配置文件 eurekaserver.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: eurekaservice1
spec:
replicas: 1
template:
metadata:
labels:
run: eurekaservice1
spec:
containers:
- name: eurekaservice1
image: docker.registry.server:5000/eurekaserver:latest
imagePullPolicy: IfNotPresent
env:
- name: spring.profiles.active
value: eurekaService1
ports:
- containerPort: 8888
2.启动
kubectl create -f eurekaserver.yaml
查看创建的pod
kubectl get pod
NAME READY STATUS RESTARTS AGE
eurekaserver-74bbd4c59b-fbvs2 0/1 ImagePullBackOff 0 10m
通过describe命令查看错误信息
kubectl describe pod eurekaserver-74bbd4c59b-fbvs2
信息如下
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 38s default-scheduler Successfully assigned eurekaserver-6b46dcd995-jvvd7 to kube-node3
Normal SuccessfulMountVolume 38s kubelet, kube-node3 MountVolume.SetUp succeeded for volume "default-token-f2vzs"
Normal Pulling 25s (x2 over 38s) kubelet, kube-node3 pulling image "docker.registry.server:5000/eurekaserver:latest"
Warning Failed 25s (x2 over 38s) kubelet, kube-node3 Failed to pull image "docker.registry.server:5000/eurekaserver:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://docker.registry.server:5000/v2/eurekaserver/manifests/latest: no basic auth credentials
Warning Failed 25s (x2 over 38s) kubelet, kube-node3 Error: ErrImagePull
Normal BackOff 11s (x2 over 37s) kubelet, kube-node3 Back-off pulling image "docker.registry.server:5000/eurekaserver:latest"
Warning Failed 11s (x2 over 37s) kubelet, kube-node3 Error: ImagePullBackOff
原因是node3并没有配置私服的密钥也没有登录私服
[root@kube-node3 ~]# docker image pull docker.registry.server:5000/eurekaserver
Using default tag: latest
Error response from daemon: Get https://docker.registry.server:5000/v2/eurekaserver/manifests/latest: no basic auth credentials
参考registry文章
1.配置/etc/hosts 加入
172.17.13.196 docker.registry.server
2.加入证书
把私服生成的证书拷贝到以下目录
/etc/docker/certs.d/docker.registry.server:5000
3.使用用户名和密码登录私服
docker login docker.registry.server:5000
输出
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
修改后查看pod
NAME READY STATUS RESTARTS AGE
eurekaserver-6b46dcd995-pb477 1/1 Running 0 10s
3.暴露服务
1.deployment暴露service
kubectl expose deploy eurekaservice1
2.查看服务
kubectl get svc
输出
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
eurekaservice1 ClusterIP 10.254.7.141 <none> 8888/TCP 13s
3.外网访问
为了通过查看eureka 需要把type: ClusterIP改为type: NodePort
通过修改命令进行修改
kubectl edit svc eurekaservice1
再查看服务
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
eurekaservice1 NodePort 10.254.7.141 <none> 8888:8905/TCP 20m
通过外网访问http://123.56.41.163:8905/可以看到eurekaserver已经启动