$$|q\rangle = \alpha|0\rangle + \beta|1\rangle$$

where \(\alpha, \beta \in \mathbb{C}\) (complex number)

- since we cannot measure global phase, we can only measure the difference in phase between the states \(|0\rangle\) and \(|1\rangle\)
Instead of complex number, confine them to the real numbers and add a term to tell us the relative phase between them:

$$|q\rangle = \alpha|0\rangle + e^{i\phi}\beta|1\rangle$$

$$\alpha, \beta, \phi \in \mathbb{R}$$

since the qubit state must be normalised: \(\sqrt{\alpha^2 + \beta^2} = 1\)

⇒ we can use the trigonometric identity: \(\sqrt{\sin^2{x} + \cos^2{x}} = 1\) to describe the real \(\alpha\) and \(\beta\) in terms of one variable \(\theta\):

$$\alpha = \cos{\tfrac{\theta}{2}}, \quad \beta=\sin{\tfrac{\theta}{2}}$$

⇒ we can describe the state of any qubit using the two variables \(\phi\) and \(\theta\)

$$|q\rangle = \cos{\tfrac{\theta}{2}}|0\rangle + e^{i\phi}\sin{\tfrac{\theta}{2}}|1\rangle$$

$$\theta, \phi \in \mathbb{R}$$

We can write any normalized (pure) state as \(|\psi\rangle = \cos{\tfrac{\theta}{2}}|0\rangle + e^{i\phi}\sin{\tfrac{\theta}{2}}|1\rangle\)
where \(\phi \in [0, 2\pi)\) describe the **relative phase** and \(\theta \in [0, \pi]\) determines the **probability to measure** \(|0\rangle , |1\rangle\): \(p(0) = \cos^2\tfrac{\theta}{2}, p(1) = \sin^2\tfrac{\theta}{2}\)

\(\Rightarrow\) all normalized pure state can be illustrated on the surface of a sphere with radius \(|\vec{r}|=1\), which we call the **Bloch sphere**

\(\Rightarrow\) the coordinates of such a state are given by the **Bloch vector** $$\vec{r} = \begin{bmatrix}\sin\theta \cos\theta \\ \sin\theta\sin\phi \\ \cos\theta\end{bmatrix} = \begin{bmatrix}x \\ y \\ z \end{bmatrix}$$

For example:

\(|0\rangle: \theta=0, \phi\) is arbitrary \(\Rightarrow \vec{r} =\begin{bmatrix}0 \\ 0 \\ 1 \end{bmatrix}\)

\(|1\rangle: \theta=\pi, \phi\) is arbitrary \(\Rightarrow \vec{r} =\begin{bmatrix}0 \\ 0 \\ -1 \end{bmatrix}\)

\(|+\rangle: \theta=\tfrac{\pi}{2}, \phi =0\) \(\Rightarrow \vec{r} =\begin{bmatrix}1 \\ 0 \\ 0 \end{bmatrix}\)

\(|-\rangle: \theta=\tfrac{\pi}{2}, \phi =\pi \Rightarrow \vec{r} =\begin{bmatrix}-1 \\ 0 \\ 0 \end{bmatrix}\)

\(|+i\rangle: \theta=\tfrac{\pi}{2}, \phi = \tfrac{\pi}{2} \Rightarrow \vec{r} =\begin{bmatrix}0 \\ 1 \\ 0 \end{bmatrix}\)

\(|-i\rangle: \theta=\tfrac{\pi}{2}, \phi = \tfrac{3\pi}{2} \Rightarrow \vec{r} =\begin{bmatrix}0 \\ -1 \\ 0 \end{bmatrix}\)

If we interpret \(\theta\) and \(\phi\) as spherical coordinates (r=1, since the magnitude of the qubit state, is 1), we can plot any single-qubit state on the surface of a sphere, known as the *Bloch sphere.*

- we have plotted a qubit in the state \(|{+}\rangle, \theta = \pi/2, \phi=0\)

An important thing to remember about qubits is that we don't care about overall phase. Hence if we have a qubit of the form: $$|\psi\rangle = e^{i\alpha}a|0\rangle + e^{i\beta}b|1\rangle = e^{i\alpha} \left( a|0\rangle + e^{i(\beta-\alpha)}b|1\rangle \right)$$ ⇒ we find the Bloch present of \(a|0\rangle + e^{i(\beta-\alpha)}b|1\rangle \)

**Example**: Represent the following qubit on Bloch Sphere
$$\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle)$$

Using \(|q\rangle = \cos{\tfrac{\theta}{2}}|0\rangle + e^{i\phi}\sin{\tfrac{\theta}{2}}|1\rangle\) ⇒ \(\cos{\tfrac{\theta}{2}}= 1/\sqrt 2 , \ e^{i\phi}\sin{\tfrac{\theta}{2}}=1/\sqrt2\)

\(\cos{\tfrac{\theta}{2}} = \cos{\tfrac{\pi}{4}} = \tfrac{1}{\sqrt2}\)

⇒ \(\theta = \tfrac{\pi}{2}\)

\(\ e^{i\phi}\sin{\tfrac{\theta}{2}}=1/\sqrt2\)

\(\sin{\tfrac{\theta}{2}} = \sin{\tfrac{\pi}{4}} = \tfrac{1}{\sqrt2}\)

\(e^{i\phi} = 1\) ⇒ \(\phi =0\) So that $$x = r

*\sin(\tfrac{\pi}{2})*\cos(0) \\ y = r*\sin(\tfrac{\pi}{2})*\sin(0) \\ z = r * \cos(\tfrac{\pi}{2})$$ \(\Rightarrow\) Cartesian Bloch Vector = [1.0, 0, 0]

**Be careful:**
On the Bloch sphere, angles are twice as big as in Hilbert space
e.g. \(|0\rangle , |1\rangle\) are orthogonal, but on the Bloch sphere, their angle is 180^0.
For a general state \(|\psi\rangle = \cos{\tfrac{\theta}{2}}|0\rangle + e^{i\phi}\sin{\tfrac{\theta}{2}}|1\rangle \Rightarrow \theta \) is the angle on the Bloch sphere, while \(\tfrac{\theta}{2}\) is the actual angle in Hibert space
\(\Rightarrow Z\)-measurement corresponds to a projection onto the z-axis and analogously for X and Y

*Classical example*: NOT gate: 0 → 1 ; 1 → 0*Quantum examples*: as quantum theory is**unitary,**i.e., quantum gates are represented by unitary matrices: \(U^\dagger U = \mathbb{I}\)*(identity matrix)*

\(\sigma_X, \sigma_Y, \sigma_Z\) are called **Pauli matrices** and \(\sigma_i^2 = \mathbb{I} = \begin{bmatrix}1 & 0 \ 0&1\end{bmatrix}\). Apply a same gates 2 times = do nothing!
→ together with identity \(\mathbb{I}\), they form a basis of 2x2 matrices

X-Gate (like classical NOT gate):

$$\sigma_X = X = \begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix} = |0\rangle\langle1| + |1\rangle\langle0|$$

X-gate switches the amplitudes of \(|0\rangle\) and \(|1\rangle\)

$$X|0\rangle = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} = |1\rangle$$

$$X|1\rangle = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} = |0\rangle$$

\(\Rightarrow\) **a bit flip** ~ classical NOT gate (but not only flip bit 0 and 1, but also **superposition**)
→ We can think of this as **a rotation by \(\pi\) radians around the x-axis of the Bloch sphere.**

$$\sigma_Z = Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = |0\rangle\langle0| - |1\rangle\langle1|$$

Apply \(\sigma_Z\) to \(|+\rangle\) and \(|-\rangle\):

$$\sigma_Z|+\rangle = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\frac{1}{\sqrt2}\begin{bmatrix}1 \\1 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \\-1 \end{bmatrix} = |-\rangle$$

$$\sigma_Z|-\rangle = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\frac{1}{\sqrt2}\begin{bmatrix}1 \\-1 \end{bmatrix} = \frac{1}{\sqrt2}\begin{bmatrix}1 \\1 \end{bmatrix} = |+\rangle$$

or \(\sigma_X|-\rangle = (|0\rangle\langle0| - |1\rangle\langle1|).\frac{1}{\sqrt2}(|0\rangle - |1\rangle) = \frac{1}{\sqrt2}(|0\rangle + |1\rangle) = |+\rangle\)

\(\Rightarrow\) **a phase flip** (rotation around the z-axis by \(\pi\))

$$\sigma_Y = Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} = -i|0\rangle\langle1| + i|1\rangle\langle0| = i.\sigma_X.\sigma_Z$$

→ rotations by \(\pi\) around the y-axis of the Bloch sphere
\(\Rightarrow\) **bit and phase flip**

It allows us to move away from the poles of the Bloch sphere and **create a superposition of \(|0\rangle\) and \(|1\rangle\):**

$$H = \tfrac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} = \tfrac{1}{\sqrt{2}}(|0\rangle\langle0|+|0\rangle\langle1| + |1\rangle\langle0| - |1\rangle\langle1|)$$

$$H|0\rangle = |+\rangle \Rightarrow H|+\rangle = |0\rangle$$

$$H|1\rangle = |-\rangle \Rightarrow H|-\rangle = |1\rangle$$

*→ Going back and forth → used to change between X and Z basis.*

This can be thought of as a rotation around the Bloch vector [1,0,1] (the line between the x & z-axis), or as transforming the state of the qubit between the X and Z bases.

- The \(R_\phi\) gate is
*parametrized,*that is, it needs a number \(\phi\) to tell it exactly what to do. The \(R_\phi\) gate performs a rotation of ϕ around the Z-axis direction (and as such is sometimes also known as the \(R_z\) gate

\(R_\phi = \begin{bmatrix} 1 & 0 \ 0 & e^{i\phi} \end{bmatrix}\) where \(\phi\) is a real number

The I, Z, S & T-gates were all special cases of the more general Rϕ-gate

The I-gate (aka ‘Id-gate’ or ‘Identity gate’). This is simply a gate that does nothing. Its matrix is the identity matrix:

$$I = \begin{bmatrix} 1 & 0 \\ 0 & 1\end{bmatrix}$$

Applying the identity gate anywhere in your circuit should have no effect on the qubit state, so it’s interesting this is even considered a gate, because:

- It is often used in calculations. For example: proving the X-gate is its own inverse: \(I = XX\)
- it is often useful when considering real hardware to specify a ‘do-nothing’ or ‘none’ operation.

S-gate (sometimes known as the \(\sqrt{Z}\) -gate), this is an \(R_\phi\) gate with \(\phi = \pi/2\)

\(S = \begin{bmatrix} 1 & 0 \\ 0 & i\end{bmatrix}\) adds \(\pi/2\) to the phase \(\phi\)

\(S|+\rangle = |+i\rangle\) and \(S|-\rangle = |-i\rangle\)

\(\Rightarrow S.H\) is applied to change from \(Z\) to \(Y\) basis

It does a

**quarter-turn**around the Bloch sphere.- It is important to note that unlike every gate introduced in this chapter so far,
**the S-gate is not its own inverse!**

\(S^\dagger\) gate, (also “S-dagger”, “Sdg” or \(\sqrt{Z}^\dagger\) gate) is \(R_\phi\) gate with \(\phi = -\pi/2\)

$$S = \begin{bmatrix} 1 & 0 \\ 0 & e^{\frac{i\pi}{2}} \end{bmatrix}, \quad S^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-\frac{i\pi}{2}} \end{bmatrix}$$

- The name "\(\sqrt{Z}\)-gate" is due to the fact that two successively applied S-gates has the same effect as one Z-gate:

$$SS|q\rangle = Z|q\rangle$$

- The T-gate is a very commonly used gate, this is an \(R_\phi\) gate with \(\phi = \pi/4\):

\(T = \begin{bmatrix} 1 & 0 \\ 0 & e^{\frac{i\pi}{4}} \end{bmatrix}, \quad T^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-\frac{i\pi}{4}} \end{bmatrix}\)

As with the S-gate, the T-gate is sometimes also known as the \(\sqrt[4]{Z}\)-gate.

The U_3\)-gate is the most general of all single-qubit quantum gates. It is a parametrized gate of the form

$$U_3(\theta, \phi, \lambda) = \begin{bmatrix} \cos(\theta/2) & -e^{i\lambda}\sin(\theta/2) \\ e^{i\phi}\sin(\theta/2) & e^{i\lambda+i\phi}\cos(\theta/2) \end{bmatrix}$$

Every gate in this chapter could be specified as \(U_3(\theta,\phi,\lambda)\), but it is unusual to see this in a circuit diagram, possibly due to the difficulty in reading this.

Qiskit provides \(U_2\) and \(U_1\) gates, which are specific cases of the \(U_3\) gate in which \(\theta=\pi/2\), and \(\theta = \phi = 0\) respectively.

- U1-gate is equivalent to the Rϕ-gate

$$\begin{aligned} U_3(\tfrac{\pi}{2}, \phi, \lambda) = U_2 = \tfrac{1}{\sqrt{2}}\begin{bmatrix} 1 & -e^{i\lambda} \\ e^{i\phi} & e^{i\lambda+i\phi} \end{bmatrix} & \quad & U_3(0, 0, \lambda) = U_1 = \begin{bmatrix} 1 & 0 \ 0 & e^{i\lambda}\\ \end{bmatrix} \end{aligned}$$

- IBM Qiskit Textbook: https://qiskit.org/textbook

Let's start with Qubits - the basic variable of quantum computers.

Classical states for computation are either 0 or 1

**Bits**: only two characters, 0 and 1, we can represent any piece of information.**Qubits**: an extension of the bit to quantum mechanics, a state can be in superposition (i.e.,**simultaneously**in 0 and 1)⇒ Superposition allows performing the calculation on many states at the same time.

⇒ Some Quantum algorithms with

**exponential speed-up**

However, once we measure the superposition state, it collapses to one of its states (0 or 1) → it is not that easy to design quantum algorithms, but we can use **interference effects**

- a quantum variant of the bit
- have exactly the same restrictions as normal bits do: they can store only a single binary piece of information and can only ever give us an output of 0 or 1.
- However, they can also be manipulated in ways that quantum mechanics can only describe.

Before finding out how to represent a qubit, let have a look at the Dirac (bra-ket) notation:

## Dirac notation

Used to describe quantum states: \( a, b \in \mathbb{C}^2 \)

ket: \( |a\rangle = \begin{bmatrix} a_1 \ a_2 \end{bmatrix} \)bra: \( \langle b| = |b\rangle ^\dagger = \begin{bmatrix}b_1 \\ b_2 \end{bmatrix} ^\dagger = \begin{bmatrix} b_1^* & b_2^* \end{bmatrix} \)

where \(b_1^*, b_2^*\) are complex conjugated of \(b_1 , b_2 \), i.e. \(b = c+d.i \Rightarrow b^* = c-d.i \)bra-ket(inner product): \( \langle b|a\rangle = a_1b_1^* + a_2b_2^* = \langle a|b\rangle^\dagger \in \mathbb{C} \)ket-bra:\( |a\rangle \langle b| = \begin{bmatrix} a_1b_1^* & a_1b_2^* \\ a_2b_1^* & a_2b_2^*\end{bmatrix} \)

Using 2 **orthogonal** vectors *(the inner product = 0)*

$$|0\rangle = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \, \, \, \, |1\rangle =\begin{bmatrix} 0 \\ 1 \end{bmatrix}$$

\( |0\rangle, |1\rangle\) are orthogonal, i.e, $$\langle 0|1\rangle = \begin{bmatrix} 1 & 0 \end{bmatrix}.\begin{bmatrix}0 \\1\end{bmatrix} = 1.0 + 0.1 =0$$

This helps us distinguish them from things like the bit values 0 and 1 or the numbers 0 and 1. It is part of the **bra-ket** notation, introduced by **Dirac**.

With vectors, we can describe more complex states than just \(|0\rangle\) and \(|1\rangle\). For example

$$ \begin{aligned} |q_0\rangle & = \tfrac{1}{\sqrt{2}}|0\rangle + \tfrac{i}{\sqrt{2}}|1\rangle \\ & = \tfrac{1}{\sqrt{2}}\begin{bmatrix}1\\0\end{bmatrix} + \tfrac{i}{\sqrt{2}}\begin{bmatrix}0\\1\end{bmatrix}\\ & = \begin{bmatrix}\tfrac{1}{\sqrt{2}}\\0\end{bmatrix} + \begin{bmatrix}0\\\tfrac{i}{\sqrt{2}}\end{bmatrix}\\ & = \begin{bmatrix}\tfrac{1}{\sqrt{2}} \\ \tfrac{i}{\sqrt{2}} \end{bmatrix}\\ \end{aligned} $$

Since the states \(|0\rangle \) and \(|1\rangle\) form an orthonormal basis, we can represent any 2D vector with a combination of these two states. This allows us to write the state of our qubit in the alternative form:

\( |q_0\rangle = \tfrac{1}{\sqrt{2}}|0\rangle + \tfrac{i}{\sqrt{2}}|1\rangle\) is a

**qubit's statevector,**Qubit Statevector it is not entirely \(|0\rangle\) and is not entirely \(|1\rangle\) ⇒ it is described by a linear combination of the two: '

**superposition**'

We choose orthogonal bases to describe and measure quantum states. During a measurement onto the bases \(|0\rangle, |1\rangle\), the states will collapse into either state \(|0\rangle\) or \(|1\rangle \) → As those are the eigenstates of \(\sigma_Z\) we call this a Z-measurement

There are infinitely many different bases, but other common ones are:

\(|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle)\) and \(|-\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle - |1\rangle)\) corresponding to the eigenstates of \(\sigma_X\)

\(|+i\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + i|1\rangle)\) and \(|-i\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle - i|1\rangle)\) corresponding to the eigenstates of \(\sigma_Y\)

The probability that a state \(|\psi\rangle\) collapse during a projective measure onto the basis \({|x\rangle, |x\rangle^\dagger}\) to the state \(|x\rangle\) is given by:

Find the probability of measuring a state \(|\psi \rangle\) in a state \(|x \rangle\):

\(p(|x\rangle) = | \langle x| \psi \rangle|^2\) and \(\sum\limits_{i} p(x_i) = 1\)

This rule governs how we get information out of quantum states. It is therefore very important for everything we do in quantum computation.

Single qubit states can be written down generally as

$$\sqrt{1-p}\vert0\rangle + e^{i\phi}\sqrt{p}\vert1\rangle$$

- \(p\) is the probability that a measurement of the state in the computational basis \({|0\rangle, |1\rangle}\) will have the outcome \(1\)
- \(\phi\) is the phase between the two computational basis states

Single-qubit gates can then be used to manipulate this quantum state by changing either \(p , \phi\) or both.

- Qiskit Textbook ( https://qiskit.org/textbook/)

Serverless(also known asFaaSorFunction-as-a-Service) is an emerging architecture that could be empowering a new generation of developers, transform the design and development of modern scalable applications. Software delivery and operation must be radically simplified. “It is important to note that serverless computing does not mean the absence of servers. The implementation still happens on real servers, but developers are relieved of installing and managing the infrastructure. The development team can then focus on the business logic and deploy the functions as soon as they are ready. These functions are completely stateless, allowing them to scale rapidly and independent from each other. As a consequence, serverless computing has made developers change the way they design, develop and deploy modern software“

- One or 2+ servers (recommended), using Ubuntu 18.04.3 (Desktop or Server version, local or remote).
*Note: These servers should have a fixed IP address.* - Internet connection

There are manifold options for deploying a local or remote Kubernetes cluster. You can find out them here . One of the easiest ways to build one is using Rancher.

Rancher is known as a platform to deliver Kubernetes-as-a-Service across any infrastructure and it could be used in both production and development environments.

In this experiment, I used 3 virtual machines running Ubuntu 18.04. All of them using sharing networking, which could connect to each other and have internet access. At least one plays a master role (Master node) and others are Worker nodes.

Docker is a mandatory ingredient and must be installed in all nodes (both Master and Worker)

```
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
```

**Option 2: Do it step-by-step**
Install docker:

```
sudo apt install -y docker.io
```

After the installation is complete, start the docker service and enable it to run it every time at system boot.

```
systemctl start docker
systemctl enable docker
```

Grant privileges to manage Docker to non-root user (don’t have to use “sudo docker”)

```
sudo groupadd docker
sudo usermod -aG docker $USER
```

You can check it using the commands below:

```
systemctl status docker
docker —version
```

Login to Master node and install Rancher. It is nothing more than running a container. Following the official docs, from your shell, enter the following command:

```
sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher
```

It will take some minutes to complete. Once it’s done, log in to Rancher by the IP `https://<server_ip>`

(replace with your Master node IP)

Then, you will be asked to setup a password for the admin account and confirm the Rancher Server URL

Login page of Rancher 2.0

After login into the Rancher dashboard, click **“Add Cluster” **on the upper right corner.

Then, select **From existing nodes (Custom)** to continue
Type Cluster name, keep other fields as default or customize them if needed

You will see the command to deploy Master and Worker nodes afterward:

There are two cases: **single node cluster **and **multi nodes cluster**

If you only have one server play the role of both Master and Worker:

- Check all boxes in part 1 – Node Options (etcd, Control Plan, Worker)
- Then, copy the command in part 2 and run it on your shell on your server. The command will be looked like:
`sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.3.2 --server https://<server_ip> --token wxhkwshb69zjk76jfrgmw8z8raabbccf98xjkv4fh92gmcrcm6d26r --ca-checksum cc2ccdb2e5a2620a4daec8de9fb100daabbccad85d8c169a1b1ddaa6fe6895d5 --etcd --controlplane --worker`

#### Multi Nodes Cluster:

If you have 2 nodes or more than, then one is Master and others are Worker. You should set up follow the following rules: - Master node: check etcd and Control Plan and use the command in part 2 to run on Master node
- Worker node: check the only Worker and use the command in part 2 to run on all Worker nodes.

*Note that, Rancher uses host name of each server as Node name by default. If you have 2 or more nodes have the same host name, you should define the different Node name for each other. Otherwise, the latter nodes couldn’t add to the Cluster.*

After that, waiting for the provisioning process (it could take some minutes). When it’s done, you can see all nodes are activated in Nodes page

Setup Cluster is done

**OpenFaaS** is a prevalent open-source platform for Serverless (besides OpenWhisk, Kubeless, Fission,…). OpenFaaS is Kubernetes-native and uses Deployments, Services, and Secrets. For more detail check out the **“faas-netes”** repository.

Presently, OpenFaaS is not available in the library of Rancher so we will need to install it by hand. Once you have a cluster, you can follow these steps. I will deploy by kubectl, you can try other options (like using Helm or k3sup by finding out on this page )

Login to Master node and run following command on your shell

```
sudo snap install kubectl --classic
```

Login to Kubernetes dashboard, on Cluster page, click **Kubeconfig File** on the upper right corner. You will see kubeconfig file in the new popup.

Main dashboard of Rancher

Then copy all and put this into the file in `/home/<user-name>/kube/config`

(create a new file if it’s not exist).
Note that, you should change the permission of this file to ensure it could be accessible by the following command: `sudo chmod 755 /home//.kube/config`

You can install the OpenFaaS CLI (to interact with CLI) using brew or a curl script.

Install OpenFaaS CLI via curl

- Via
**curl**:`curl -sL https://cli.openfaas.com | sudo sh`

- Via
**brew**:`brew install faas-cli`

Clone the repository:

```
git clone https://github.com/openfaas/faas-netes
```

Deploy the whole stack: This command is split into two parts so that the OpenFaaS namespaces are always created first:

**openfaas**– for OpenFaaS services**openfaas-fn**– for functions Enter to faas-netes folder and deploy openfass and openfaas-fn namespace

Create a password for the gateway:`cd faas-netes kubectl apply -f namespaces.yml --kubeconfig=/home/<user-name>/.kube/config`

```
# Generate a random password
PASSWORD=$(head -c 12 /dev/urandom | shasum| cut -d' ' -f1)
kubectl -n openfaas create secret generic basic-auth \
--from-literal=basic-auth-user=admin \
--from-literal=basic-auth-password="$PASSWORD"
```

**Note**: You can use your own password and remember it to log in to OpenFaaS UI. If using the above command to generate a random password, then review and keep it (using `echo $PASSWORD`

)

In faas-netes folder, run following command:

```
kubectl apply -f ./yaml --kubeconfig=/home/<user-name>/.kube/config
```

Back to the Rancher dashboard, navigate to Projects/Namespace, you will see 2 namespaces openfaas and openfaas-fn are created. Then, click Add Project on the upper right corner, enter Project Name (like openfaas or other up to you) and click Create. Next, select 2 openfaas namespaces and click Move button (on upper left corner) to move them to Project openfaas you have just created. Result:

Create OpenFaaS project

When clicking on your project, you will see all your Workloads

All workloads after deploy OpenFaaS

Select **Load balancing** section, then click **Add Ingress** on the upper right corner. Type Ingress name, select Target is gateway workload, port like 8080, keep others fields á default and click **Save**.

Setup Gateway Ingress

```
export OPENFAAS_URL=gateway.openfaas.<your_gateway_IP>.xip.io
```

Now, you can access OpenFaaS URL via the URL `gateway.openfaas.<server-ip>.xip.io`

(in Targets) section and login with username admin and password in step 3

Congratulation! OpenFaaS deployment on Rancher is completed and you can play with Serverless now.

https://github.com/openfaas/faas ↩

]]>