New rc (replication controller)
Do the following in the master1
rc is to configure a set of procedures to deploy, k8s will run automatically according to configuration and management procedures, such as start automatically, the program automatically restart and so hung up
rc configuration are generally written to the configuration file (extension yaml), and then specify the file to create a new yaml rc, k8s a lot of "stuff" is configured in this manner
In any directory (preferably a place to store documents and materials), the new file springboot-helloworld-rc.yaml, reads as follows:
PS: There are some items Comment
apiVersion: v1
kind: ReplicationController # object type, here is rc (full name ReplicationController)
metadata:
name: helloworld # Name
labels:
name: helloworld # label
spec:
replicas: 3 # copy running container number, where you can modify quickly modify the number of distributed nodes
selector:
name: helloworld
template:
metadata:
labels:
name: helloworld
spec:
containers: container arranged #docker
- name: helloworld
image: 192.168.31.141:5000/springio/ewater:0.0.1#pull mirrored address
imagePullPolicy: IfNotPresent # pull mirroring opportunity,
ports:
- containerPort: 20801 # other open container port
yaml cd to the directory, run: kubectl create -f springboot-helloworld-rc.yaml, according to yaml create rc configuration (create what type of object is specified in the yaml inside, create a command to all types of objects are kubectl create)
Run: kubectl get rc, you can view a list of rc
Run: kubectl get pods, pod can view a list of running
Pod start more error-prone, the following details:
First pod can be understood as docker container, such as paper rc configured to run a copy of the (container) number is 3, so we created a 3 pod (container)
Pod state (status) is running (running) is normal, if it is not successfully start another Value Description
There may be unsuccessful pull mirroring slower, this can only wait
No success is also possible that fails to start, you can use the command kubectl describe pod helloworld-7jpm5 (helloworld-7jpm5 representatives pod name), to debug a pod start by looking at the log
For example, when the problem described in FIG pull on the mirror
Also you can use the command kubectl logs helloworld-7jpm5 (helloworld-7jpm5 Representative pod Title) command log pod view, corresponding to the operation command cmd jar package line output
rc and pod successfully created and run, the equivalent of java program has been running successfully in k8s, but also outside the network can not access, then you want to create service
New service
Do the following in the master1
Service in k8s system overall responsibility for internal and external communication k8s network configuration (note that only refers to internal and external k8s inside and outside the network, rather than a local area network and the Internet)
In any directory (preferably a place to store documents and materials), the new file springboot-helloworld-svc.yaml, reads as follows:
apiVersion: v1
kind: Service # object type, here is the service
metadata:
name: helloworld # Name
labels:
name: helloworld # label
spec:
type: NodePort
ports:
- port: 20801 #service (internal) ports
targetPort: 20801 #pod port
nodePort: 32008 #service external port
selector:
name: helloworld
cd to yaml file directory, run: kubectl create -f springboot-helloworld-svc.yaml, create a service based on yaml file
Kubectl get services you can run to see the new service
PS: 20801 is an internal port, external port is 32008
At this time, whether to deploy in the browser can access the test is successful, note that ip is master1, the port is the external port service