1. Install Virtualbox
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
Install minikube in Ubuntu:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Install kubectl in Ubuntu:
curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
minikube start --vm-driver=virtualbox
5. After a few minutesthe minikube instance will be ready. then use kubectl to verify that everything is working:
kubectl cluster-info
result should be: Kubernetes master is running at https://192.168.99.100:8443 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
minikube dashboard
minikube stop
- http://www.admintome.com/blog/minikube-introduction/
- https://github.com/kubernetes/minikube/blob/v0.24.1/README.md
- https://kubernetes-v1-4.github.io/docs/getting-started-guides/minikube/#install-minikube
- https://www.youtube.com/watch?v=GqyJgvTgqq4
var http = require('http');
var handleRequest = function(request, response) {
console.log('Received request for URL: ' + request.url);
response.writeHead(200);
response.end('Hello World!');
};
var www = http.createServer(handleRequest);
www.listen(8080);
Create a file, also in the hellonode folder, named 'Dockerfile':
FROM node:6.9.2
EXPOSE 8080
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY server.js .
CMD node server.js
(NOTE: You can run 'node -v' to check your node version in terminal)
eval $(minikube docker-env)
Later, when you no longer wish to use the Minikube host, you can undo this change by running eval
$(minikube docker-env -u).
docker build -t hello-node:v1 .
kubectl run hello-node --image=hello-node:v1 --port=8080
View the Deployment:
kubectl get deployments
View the Pod:
kubectl get pods
kubectl expose deployment hello-node --type=NodePort
Change '--type=NodePort' to '--type=LoadBalancer' if LoadBalancer is setting up
View the Service you just created:
kubectl get services
Output should look like:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node 10.0.0.71 <pending> 8080:3xxxx/TCP 6m
kubernetes 10.0.0.1 <none> 443/TCP 14d
(NOTE: The --type=LoadBalancer flag indicates that you want to expose your Service outside of the cluster. On cloud providers that support load balancers, an external IP address would be provisioned to access the Service. If load balancer is supported,the above output result will show the EXTERNAL-IP. But minikube dones't support load balancers, it's always pending)
minikube service hello-node
Edit the server.js file to return a new message:
response.end('Hello World Again!');
Build a new version of your image:
docker build -t hello-node:v2 .
Update the image of your Deployment:
kubectl set image deployment/hello-node hello-node=hello-node:v2
Run your app again to view the new message:
minikube service hello-node
kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-node 1 1 1 1 1h
kubectl scale deployments/hello-node --replicas=4
kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-node 4 4 4 1 1h
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
hello-node-75ddf8bc9d-2xnlh 1/1 Running 0 1m 172.17.0.7 minikube
hello-node-75ddf8bc9d-9xhgj 1/1 Running 0 1h 172.17.0.5 minikube
hello-node-75ddf8bc9d-gh7xx 1/1 Running 0 1m 172.17.0.6 minikube
hello-node-75ddf8bc9d-vxs4k 1/1 Running 0 1m 172.17.0.4 minikube
(Now their are 4 running pods)
kubectl delete deployment hello-node
kubectl delete service hello-node
mkdir /demo/application1
cd /demo/application1
vim example.app1.deployment.yaml file
insert the code:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-node
spec:
replicas: 1
template:
metadata:
labels:
app: hello-node
tier: hello-app
trcak: stable
spec:
containers:
- name: hello-node
image: "hello-node:v1"
ports:
- containerPort: 8080
vim example.app1.service.yaml file
insert the code:
apiVersion: v1
kind: Service
metadata:
name: hello-node
spec:
selector:
app: hello-node
tier: hello-app
ports:
- protocol: "TCP"
port: 80
targetPort: 8080
type: NodePort
deployment:
kubectl create -f example.app1.deployment.yaml
service:
kubectl create -f example.app1.service.yaml
Or all yaml file in current directory
kubectl create -f .
To view the running deployment and service:
kubectl get deployments
kubectl get service
kind: PersistentVolume
apiVersion: v1
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/demo/html/hello-node"
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: task-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
edit example.app1.deployment.yaml file
vim example.app1.deployment.yaml file
Update it to:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-node
spec:
replicas: 1
template:
metadata:
labels:
app: hello-node
tier: hello-app
trcak: stable
spec:
containers:
- name: hello-node
image: "hello-node:v2"
ports:
- containerPort: 8085
volumeMounts:
- name: simple-storage
mountPath: /usr/src/app
volumes:
- name: simple-storage
persistentVolumeClaim:
claimName: task-pv-claim