When I specify a Deployment in a kubernetes yaml file, for example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
selector:
matchLabel:
deploy: example
template:
metadata:
labels:
deploy: example
spec:
containers:
- name: my-container
image: dockerhub.com/imagerepo:latest
I'm wondering what's going on in the backend to run my deploy:example pod. I'm guessing some sort of docker run <image> && docker start <image> command is executed on each node, but what exactly is the command?
Related
Heres image of my Kubernetes services.
Todo-front-2 is working instance of my app, which I deployed with command line:
kubectl run todo-front --image=todo-front:v7 --image-pull-policy=Never
kubectl expose deployment todo-front --type=NodePort --port=3000
And it's working great. Now I want to move on and use todo-front.yaml file to deploy and expose my service. Todo-front service refers to my current try on it. My deployment file looks like this:
kind: Deployment
apiVersion: apps/v1
metadata:
name: todo-front
spec:
replicas: 1
selector:
matchLabels:
app: todo-front
template:
metadata:
labels:
app: todo-front
spec:
containers:
- name: todo-front
image: todo-front:v7
env:
- name: REACT_APP_API_ROOT
value: "http://localhost:12000"
imagePullPolicy: Never
ports:
- containerPort: 3000
---
kind: Service
apiVersion: v1
metadata:
name: todo-front
spec:
type: NodePort
ports:
- port: 3000
targetPort: 3000
selector:
app: todo-front
I deploy it using:
kubectl apply -f deployment/todo-front.yaml
Here is the output
But when I run
minikube service todo-front
It redirects me to URL saying "Site can't be reached".
I can't figure out what I'm doing wrong. Ports should be ok, and my cluster should be ok since I can get it working by only using command-line without external YAML files. Both deployments are also using the same docker-image. I have also tried changing all ports now "3000" to something different, in case they clash with existing deployment todo-front-2, no luck.
Here is also a screenshot of pods and their status:
Anyone with more experience with Kube and Docker cares to take a look? Thank you!
You can run below commands to generate the yaml files without applying it to the cluster and then compare it with the yamls you manually created and see if there is a mismatch. Also instead of creating yamls manually yourself you can apply the generated yamls itself.
kubectl run todo-front --image=todo-back:v7 --image-pull-policy=Never --dry-run -o yaml > todo-front.yaml
kubectl expose deployment todo-front --type=NodePort --port=3000 --dry-run -o yaml > todo-depoloyment.yaml
I have an application, which I deployed with docker run and it worked fine. Now I am trying to run that application on Kubernetes.
I have tried to build my deployment.yaml file but not able to complete it getting validation error.
Below is my docker run command
docker run -e LICENSE="accept" -d --name=container1 -p 10000:10000 -v /opt/app/install:/install/resources appCentre:6.0.0 appCentre_setup deploy_setup
and deployment.yaml file I am trying to build
apiVersion: apps/v1
kind: Deployment
metadata:
name: appCentre
labels:
app: appCentre
spec:
replicas: 1
selector:
matchLabels:
app: appCentre
template:
metadata:
labels:
app: appCentre
spec:
containers:
- name: appCentre
image: appCentre:6.0.0
args:
- "appCentre_setup"
- "deploy_setup"
ports:
- containerPort: 10000
volumnMounts:
- name: volumn-app-appCentre
mountPath: /install/resources
volumns:
- name: volumn-app-appCentre
hostPath:
path: /opt/app/install
type: Directory
How can I proceed?
The easiest way would be to generate the base yaml using:
kubectl run appCentre --image=appcentre:6.0.0 -l app=appCentre --expose --port=1000 --env=LICENSE="accept" --dry-run -o yaml
and then modify for your needs.
You should also check here as #mchawre point.
I hope this helps.
Integrated kubernetes with jenkins and run the command in Jenkins file kubectl create -f deployment.yaml --validate=false and getting the error:
unable to recognize "deployment.yaml": no matches for extensions/,Kind=Deployment
But if I run the same command in terminal I am able to deploy my image. deployment.yaml file is given below
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: appname
spec:
template:
metadata:
labels:
app: appname
spec:
containers:
- name: appname
image: appname
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
I suppose your minikube (if you are checking in your local machine) is NOT running.
Start minikube using the following command
$minikube start
Now try
$kubectl create OR
$kubectl apply
I want to run a private docker image on my minikube k8s .
But the pod is never able to pull my image from docker .
How can i pull private image in k8s and use it?
This my yaml for pod
{apiVersion: v1
kind: Pod
metadata:
name: privaterepo
spec:
containers:
- name: private-reg-container
image: raveena1/test
imagePullSecrets:
- name: regsecret}
The log is:-
container "private-reg-container" in pod "privaterepo" is waiting to start: trying and failing to pull image
You need to create a secret & use it in your YAML/JSON deployment file -
Create secret (Like for Docker registry, you can change the registry server URL) -
$ kubectl create secret docker-registry regsecret --docker-server=https://index.docker.io/v1/ --docker-username=$USERNM --docker-password=$PASSWD --docker-email=vivekyad4v#gmail.com
deployment.yaml (use regsecret)-
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: local-simple-python
spec:
replicas: 2
selector:
matchLabels:
app: local-simple-python
template:
metadata:
labels:
app: local-simple-python
spec:
containers:
- name: python
image: vivekyad4v/local-simple-python:latest
ports:
- containerPort: 8080
imagePullSecrets:
- name: regsecret
Deploy -
$ kubectl create -f deployment.yml
Your pods should now be able to fetch docker images on private registry.
You can find more info on -
https://github.com/vivekyad4v/kubernetes/tree/master/kubernetes-for-beginners
Official doc - https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
I'm quite new to kubernetes, and I'm trying to deploy a docker container to kubernetes. I already have a docker container running on AWS. I am trying to deploy the yml file through the following command:
kops create -f deployment.yml --state=s3://mybucket
However whenever I try to deploy my yml file, I get a message saying:
error parsing file "deployment.yml": no kind "Cluster" is registered for version "v1"
My yml file looks like this:
apiVersion: v1
kind: Cluster
metadata:
name: containers
spec:
containers:
- name: container
image: [idnumber].dkr.ecr.eu-west-2.amazonaws.com/myfirstcontainer
ports:
- containerPort: 3000
Grateful for any help!
Thanks
There is no kind: Cluster in kubernetes API v1.
You should use kind: Pod if you want to run only one pod or use deployment, if you want to create controller which manages your pod:
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
Also, you have some issues with formatting in your deployment.yml file.
The final deployment.yml should be for pod:
apiVersion: v1
kind: Pod
metadata:
name: containers
spec:
containers:
- name: container
image: [idnumber].dkr.ecr.eu-west-2.amazonaws.com/myfirstcontainer
ports:
- containerPort: 3000
or for deployment:
apiVersion: apps/v1beta1 # for versions starting from 1.8.0 use apps/v1beta2
kind: Deployment
metadata:
name: containers
spec:
replicas: 1
selector:
matchLabels:
app: some_app
template:
metadata:
labels:
app: some_app
spec:
containers:
- name: container
image: [idnumber].dkr.ecr.eu-west-2.amazonaws.com/myfirstcontainer
ports:
- containerPort: 3000