When we use the pod, the pod can ping each other before, the machine itself can ping another pod and pod machine, if it is a serivce, we pass the port number, you can access the service. Source: https://github.com/limingios/docker/tree/master/No.10
Do not direct the use and management Pods, Why?
- When we do use ReplicaSet or ReplicationController horizontal expansion of scale, Pods may be ending.
- When we use the Deployment of us to update Docker Image Version, old Pods will be over, and then create a new Pods, Ip address has changed.
Service
- kubectl expoese command will give us the pod to create a Service, for external access.
- Service There are three main types:
- ClsterIP
- NodePort
- LoadBalancer
- Alternatively, you can use DNS, but requires a DNS add-on
Service demo
- Create a service.
get pod
kubectl get pod -o wide
kubectl expose pods nginx
#查看到已经创建的service
kubectl get svc
- Access service
ping 10.254.233.245
- Creating deployment
cd deployk8s-master/
cd labs/
cd deployment/
more deployment_nginx.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.12.2
ports:
- containerPort: 80
kubectl create -f deployment_nginx.yml
kubectl get pods -o wide
We enter the node node to access these deployment
- Creating deploy the corresponding service
kubectl get deployment
expose deployment nginx-deployment
kubectl get svc
Modify the deployment of internal service
kubectl edit deployment nginx-deployment
PS: According to modify the contents of your file, it will automatically update, but did not change ip, this is the service of the powerful. But in its current form direct change deloyment files, not recommended because he is not a rollover, the next time that the next rollover.