一,nginx_deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx readinessProbe: exec: command: - cat - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5
*注意,yaml里面得label字段,service通过label字段,来和pod形式对应关系
二:创建nginx服务pod
k create -f nginx-deploy.yaml
三,service得yaml
apiVersion: v1 kind: Service metadata: name: nginx-basic spec: type: ClusterIP ports: - port: 80 protocol: TCP name: http selector: app: nginx
* 注意selector字段,通过selector字段,来找到对应得pod
四,创建service
k create -f service.yaml
五,nginx一直没有ready, 查看:
k describe po nginx-deployment-57586646f7-gknvs
六,缺少健康检查文件, 容器里创建一个:
k exec -it nginx-deployment-57586646f7-gknvs -- touch /tmp/healthy
七,pod ready之后,查看一下endpoint,endpoint里存放service和pod得对应关系
八,测试service是否可用,这个虚拟ip只能在集群内测试使用:
curl 10.108.185.127
九: 如果想集群外访问这个服务,需要修改下service 类型:
九:可以通过节点ip:31135 来访问nginx服务了
然而并没有通,待解