- 验证实验
[zhoujing@zhouj Code]$ git clone https://github.com/wardviaene/kubernetes-course
正克隆到 'kubernetes-course'...
remote: Counting objects: 90, done.
remote: Total 90 (delta 0), reused 0 (delta 0), pack-reused 90
展开对象中: 100% (90/90), 完成.
[zhoujing@zhouj Code]$ cd kubernetes-course/
[zhoujing@zhouj kubernetes-course]$ kubectl get node
NAME STATUS AGE VERSION
minikube Ready 1d v1.7.0
[zhoujing@zhouj kubernetes-course]$ cat first-app/helloworld.yml
apiVersion: v1
kind: Pod
metadata:
name: nodehelloworld.example.com
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000
- 创建pod
[zhoujing@zhouj kubernetes-course]$ kubectl create -f first-app/helloworld.yml
pod "nodehelloworld.example.com" created
[zhoujing@zhouj kubernetes-course]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-180744149-r908g 1/1 Running 1 2h
nodehelloworld.example.com 0/1 ContainerCreating 0 2m
- 描述pod相关信息
[zhoujing@zhouj kubernetes-course]$ kubectl describe pod nodehelloworld.example.com
Name: nodehelloworld.example.com
Namespace: default
Node: minikube/192.168.99.100
Start Time: Wed, 02 Aug 2017 17:40:49 +0800
Labels: app=helloworld
Annotations: <none>
Status: Pending
IP:
Containers:
k8s-demo:
Container ID:
Image: wardviaene/k8s-demo
Image ID:
Port: 3000/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-23mkf (ro)
Conditions:
Type Status
Initialized True
Ready False
[zhoujing@zhouj kubernetes-course]$ kubectl describe pod nodehelloworld.example.com
Name: nodehelloworld.example.com
Namespace: default
Node: minikube/192.168.99.100
Start Time: Wed, 02 Aug 2017 17:40:49 +0800
Labels: app=helloworld
Annotations: <none>
Status: Pending
IP:
Containers:
k8s-demo:
Container ID:
Image: wardviaene/k8s-demo
Image ID:
Port: 3000/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-23mkf (ro)
Conditions:
Type Status
Initialized True
Ready False
- 显示本地端口,访问查看信息
[zhoujing@zhouj kubernetes-course]$ kubectl port-forward nodehelloworld.example.com 8081:3000
Forwarding from 127.0.0.1:8081 -> 3000
Forwarding from [::1]:8081 -> 3000
Handling connection for 8081
#在浏览器端口输入:localhost:8081,显示信息内容如下:
Hello World!
- 暴露pod的端口;显示访问地址
[zhoujing@zhouj kubernetes-course]$ kubectl expose pod nodehelloworld.example.com --type=NodePort
The Service "nodehelloworld.example.com" is invalid: metadata.name: Invalid value: "nodehelloworld.example.com": a DNS-1035 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
[zhoujing@zhouj kubernetes-course]$ kubectl expose pod nodehelloworld.example.com --type=NodePort --name nodehelloworld-dervice
service "nodehelloworld-dervice" exposed
[zhoujing@zhouj kubernetes-course]$ minikube service nodehelloworld-dervice --url
http://192.168.99.100:30602
浏览网页,显示内容如下:
Hello World!
- 查看service信息
[zhoujing@zhouj kubernetes-course]$ kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube 10.0.0.38 <nodes> 8080:30299/TCP 2h
kubernetes 10.0.0.1 <none> 443/TCP 1d
nodehelloworld-dervice 10.0.0.247 <nodes> 3000:30602/TCP 3m