You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1beta2kind: Deploymentmetadata:
name: nginx-deploymentspec:
selector:
matchLabels:
app: nginxreplicas: 2# tells deployment to run 2 pods matching the templatetemplate: # create pods using pod definition in this templatemetadata:
# unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is# generated from the deployment namelabels:
app: nginxspec:
containers:
- name: nginximage: nginx:1.7.9ports:
- containerPort: 80
1. Create a Deployment based on the YAML file
$ kubectl apply -f https://k8s.io/docs/tasks/run-application/deployment.yaml
deployment "nginx-deployment" created
2. Display information about the Deployment
$ kubectl describe deployment nginx-deployment
Name: nginx-deployment
Namespace: default
CreationTimestamp: Sun, 05 Nov 2017 11:53:47 +0900
Labels: app=nginx
Annotations: deployment.kubernetes.io/revision=1
kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"apps/v1beta2","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},"spec":{"replicas":2,"se...
Selector: app=nginx
Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx:1.7.9
Port: 80/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deployment-569477d6d8 (2/2 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set nginx-deployment-569477d6d8 to 2
3. List the pods created by the deployment:
$ kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-569477d6d8-79gv7 1/1 Running 0 4m
nginx-deployment-569477d6d8-8qkvm 1/1 Running 0 4m
4. Display information about a pod
$ kubectl describe pod nginx-deployment
Name: nginx-deployment-569477d6d8-79gv7
Namespace: default
Node: minikube/192.168.99.101
Start Time: Sun, 05 Nov 2017 11:53:47 +0900
Labels: app=nginx
pod-template-hash=1250338284
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"nginx-deployment-569477d6d8","uid":"8b322ac5-c1d4-11e7-a4b5-0800...
Status: Running
IP: 172.17.0.5
Created By: ReplicaSet/nginx-deployment-569477d6d8
Controlled By: ReplicaSet/nginx-deployment-569477d6d8
Containers:
nginx:
Container ID: docker://8b602b3dfc90f6490921bc03aa450472e6f92b89ba50775d49b1fbe6f820da58
Image: nginx:1.7.9
Image ID: docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451
Port: 80/TCP
State: Running
Started: Sun, 05 Nov 2017 11:53:47 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-p7qcn (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-p7qcn:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-p7qcn
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m default-scheduler Successfully assigned nginx-deployment-569477d6d8-79gv7 to minikube
Normal SuccessfulMountVolume 6m kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-p7qcn"
Normal Pulled 6m kubelet, minikube Container image "nginx:1.7.9" already present on machine
Normal Created 6m kubelet, minikube Created container
Normal Started 6m kubelet, minikube Started container
Name: nginx-deployment-569477d6d8-8qkvm
Namespace: default
Node: minikube/192.168.99.101
Start Time: Sun, 05 Nov 2017 11:53:47 +0900
Labels: app=nginx
pod-template-hash=1250338284
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"nginx-deployment-569477d6d8","uid":"8b322ac5-c1d4-11e7-a4b5-0800...
Status: Running
IP: 172.17.0.4
Created By: ReplicaSet/nginx-deployment-569477d6d8
Controlled By: ReplicaSet/nginx-deployment-569477d6d8
Containers:
nginx:
Container ID: docker://f3eaaa96c7ea3c3a12a416d4a113e24699e72f585e799c4fd22d7079c1d94f7b
Image: nginx:1.7.9
Image ID: docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451
Port: 80/TCP
State: Running
Started: Sun, 05 Nov 2017 11:53:47 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-p7qcn (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
default-token-p7qcn:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-p7qcn
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m default-scheduler Successfully assigned nginx-deployment-569477d6d8-8qkvm to minikube
Normal SuccessfulMountVolume 6m kubelet, minikube MountVolume.SetUp succeeded for volume "default-token-p7qcn"
Normal Pulled 6m kubelet, minikube Container image "nginx:1.7.9" already present on machine
Normal Created 6m kubelet, minikube Created container
Normal Started 6m kubelet, minikube Started container
Updating the deployment
apiVersion: apps/v1beta2kind: Deploymentmetadata:
name: nginx-deploymentspec:
selector:
matchLabels:
app: nginxreplicas: 2template:
metadata:
labels:
app: nginxspec:
containers:
- name: nginximage: nginx:1.8 # Update the version of nginx from 1.7.9 to 1.8ports:
- containerPort: 80
$ kubectl describe deployments
Name: nginx-deployment
Namespace: default
CreationTimestamp: Sun, 05 Nov 2017 16:38:01 +0900
Labels: app=nginx
Annotations: deployment.kubernetes.io/revision=3
Selector: app=nginx
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=nginx
Containers:
nginx:
Image: nginx:1.9.0
Port: 80/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deployment-779765c687 (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 1h deployment-controller Scaled up replica set nginx-deployment-569477d6d8 to 3
Normal ScalingReplicaSet 16m deployment-controller Scaled up replica set nginx-deployment-6bd4859cdb to 1
Normal ScalingReplicaSet 16m deployment-controller Scaled down replica set nginx-deployment-569477d6d8 to 2
Normal ScalingReplicaSet 16m deployment-controller Scaled up replica set nginx-deployment-6bd4859cdb to 2
Normal ScalingReplicaSet 16m deployment-controller Scaled down replica set nginx-deployment-569477d6d8 to 1
Normal ScalingReplicaSet 16m deployment-controller Scaled up replica set nginx-deployment-6bd4859cdb to 3
Normal ScalingReplicaSet 16m deployment-controller Scaled down replica set nginx-deployment-569477d6d8 to 0
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set nginx-deployment-779765c687 to 1
Normal ScalingReplicaSet 3m deployment-controller Scaled down replica set nginx-deployment-6bd4859cdb to 2
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set nginx-deployment-779765c687 to 2
Normal ScalingReplicaSet 3m deployment-controller Scaled down replica set nginx-deployment-6bd4859cdb to 1
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set nginx-deployment-779765c687 to 3
Normal ScalingReplicaSet 3m deployment-controller Scaled down replica set nginx-deployment-6bd4859cdb to 0
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.2", GitCommit:"bdaeafa71f6c7c04636251031f93464384d54963", GitTreeState:"clean", BuildDate:"2017-10-24T21:07:53Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"}
$ which kubectl
/usr/local/bin/kubectl
minikube
Install
brew cask install minikube
どこにインストールされたか
$ which minikube /usr/local/bin/minikube
version
$ minikube version
minikube version: v0.23.0
help
$ minikube
Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows.
Usage:
minikube [command]
Available Commands:
addons Modify minikube's kubernetes addons
completion Outputs minikube shell completion for the given shell (bash)
config Modify minikube config
dashboard Opens/displays the kubernetes dashboard URL for your local cluster
delete Deletes a local kubernetes cluster
docker-env Sets up docker env variables; similar to '$(docker-machine env)'
get-k8s-versions Gets the list of available kubernetes versions available for minikube
ip Retrieves the IP address of the running cluster
logs Gets the logs of the running localkube instance, used for debugging minikube, not user code
mount Mounts the specified directory into minikube
profile Profile sets the current minikube profile
service Gets the kubernetes URL(s) for the specified service in your local cluster
ssh Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'
ssh-key Retrieve the ssh identity key path of the specified cluster
start Starts a local kubernetes cluster
status Gets the status of a local kubernetes cluster
stop Stops a running local kubernetes cluster
update-context Verify the IP address of the running cluster in kubeconfig.
version Print the version of minikube
Flags:
--alsologtostderr log to standard error as well as files
-b, --bootstrapper string The name of the cluster bootstrapper that will set up the kubernetes cluster. (default "localkube")
-h, --help help for minikube
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--loglevel int Log level (0 = DEBUG, 5 = FATAL) (default 1)
--logtostderr log to standard error instead of files
-p, --profile string The name of the minikube VM being used.
This can be modified to allow for multiple minikube instances to be run independently (default "minikube")
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
Use "minikube [command] --help" for more information about a command.
$ minikube start
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Downloading Minikube ISO
140.01 MB / 140.01 MB [============================================] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Downloading localkube binary
148.56 MB / 148.56 MB [============================================] 100.00% 0s
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
$ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
deployment "hello-minikube" created
$ kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-5bc754d4cd-db5mj 1/1 Running 0 1m
$ curl $(minikube service hello-minikube --url)
CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://192.168.99.100:8080/
SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001
HEADERS RECEIVED:
accept=*/*
host=192.168.99.100:30068
user-agent=curl/7.54.0
BODY:
-no body in request-%
$ minikube service hello-minikube --url
http://192.168.99.100:30068
$ minikube stop
Stopping local Kubernetes cluster...
Machine stopped.
$ kubectl get pod
Unable to connect to the server: dial tcp 192.168.99.100:8443: getsockopt: operation timed out
https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/